Advanced People Service

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.

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:

advanced/people.gs
/**
 * Gets a list of people in the user's contacts.
 */
function getConnections() {
  var people = People.People.Connections.list('people/me', {
    personFields: 'names,emailAddresses'
  });
  Logger.log('Connections: %s', JSON.stringify(people, null, 2));
}

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:

advanced/people.gs
/**
 * Gets the own user's profile.
 */
function getSelf() {
  var people = People.People.getBatchGet({
    resourceNames: ['people/me'],
    personFields: 'names,emailAddresses'
  });
  Logger.log('Myself: %s', JSON.stringify(people, null, 2));
}

Get the person for a Google Account

To get the person information for any Google Account, use the following code:

advanced/people.gs
/**
 * Gets the person information for any Google Account.
 * @param {string} accountId The account ID.
 */
function getAccount(accountId) {
  var people = People.People.get('people/' + accountId, {
    personFields: 'names,emailAddresses'
  });
  Logger.log('Public Profile: %s', JSON.stringify(people, null, 2));
}

Enviar comentarios sobre…

¿Necesitas ayuda? Visita nuestra página de asistencia.