Advanced People Service
Stay organized with collections
Save and categorize content based on your preferences.
Page Summary
-
The advanced People service in Apps Script utilizes the People API to manage contact and profile data.
-
This is an advanced service that requires explicit enablement before use.
-
The service uses the same objects, methods, and parameters as the public People API.
-
Sample code is provided to demonstrate getting user connections, the user's own profile, and information for any Google Account.
The advanced People service allows you to use the People API in Apps Script. This API allows scripts to create, read, and update contact data for the logged in user and read profile data for google users.
Reference
For detailed information on this service, see the reference documentation for the People API. Like all advanced services in Apps Script, the advanced People service uses the same objects, methods, and parameters as the public API. For more information, see How method signatures are determined.
To report issues and find other support, see the People v1 support guide.
Sample code
The sample code below uses version 1 of the API.
Get the user's connections
To get a list of people in the user's contacts, use the following code:
/** * 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 profile constpeople=People.People.Connections.list("people/me",{ personFields:"names,emailAddresses", }); // Print the connections/contacts console.log("Connections: %s",JSON.stringify(people,null,2)); }catch(err){ // TODO (developers) - Handle exception here console.log("Failed to get the connection with an error %s",err.message); } }
Get the person for the user
To get the user's profile, you need to request
the https://www.googleapis.com/auth/userinfo.profile scope by following the
instructions to add explicit scopes
to your appsscript.json manifest file. Once the scope is added, you can use
the following code:
/** * 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() method constpeople=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 exception console.log("Failed to get own profile with an error %s",err.message); } }
Get the person for a Google Account
To get the person information for any Google Account, use the following code:
/** * 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 exception console.log("Failed to get account with an error %s",err.message); } }