高度な People サービスを使用すると、Apps Script で People API を使用できます。この API を使用すると、スクリプトでログイン ユーザーの連絡先データの作成、読み取り、更新を行ったり、Google ユーザーのプロフィール データを読み取ったりできます。
リファレンス
このサービスの詳細については、People API のリファレンス ドキュメントをご覧ください。Apps Script のすべての高度なサービスと同様に、高度な People サービスでは、公開 API と同じオブジェクト、メソッド、パラメータを使用します。詳細については、メソッド シグネチャの決定方法をご覧ください。
/** * Gets a list of people in the user's contacts. * @see https://developers.google.com/people/api/rest/v1/people.connections/list */functiongetConnections(){try{// Get the list of connections/contacts of user's profileconstpeople=People.People.Connections.list("people/me",{personFields:"names,emailAddresses",});// Print the connections/contactsconsole.log("Connections: %s",JSON.stringify(people,null,2));}catch(err){// TODO (developers) - Handle exception hereconsole.log("Failed to get the connection with an error %s",err.message);}}
/** * Gets the own user's profile. * @see https://developers.google.com/people/api/rest/v1/people/getBatchGet */functiongetSelf(){try{// Get own user's profile using People.getBatchGet() methodconstpeople=People.People.getBatchGet({resourceNames:["people/me"],personFields:"names,emailAddresses",// Use other query parameter here if needed});console.log("Myself: %s",JSON.stringify(people,null,2));}catch(err){// TODO (developer) -Handle exceptionconsole.log("Failed to get own profile with an error %s",err.message);}}
/** * Gets the person information for any Google Account. * @param {string} accountId The account ID. * @see https://developers.google.com/people/api/rest/v1/people/get */functiongetAccount(accountId){try{// Get the Account details using account ID.constpeople=People.People.get(`people/${accountId}`,{personFields:"names,emailAddresses",});// Print the profile details of Account.console.log("Public Profile: %s",JSON.stringify(people,null,2));}catch(err){// TODO (developer) - Handle exceptionconsole.log("Failed to get account with an error %s",err.message);}}