Zaawansowana usługa osób

Zaawansowana usługa Osoby pozwala na korzystanie z interfejsu People API w Apps Script. Ten interfejs API umożliwia skryptom tworzenie, odczytywanie i aktualizowanie danych kontaktowych zalogowanego użytkownika oraz odczytywanie danych profilowych użytkowników Google.

Dokumentacja

Szczegółowe informacje o tej usłudze znajdziesz w dokumentacji interfejsu People API. Podobnie jak wszystkie usługi zaawansowane w Apps Script, zaawansowana usługa Osoby korzysta z tych samych obiektów, metod i parametrów co publiczny interfejs API. Więcej informacji znajdziesz w artykule Jak określane są podpisy metod.

Aby zgłosić problemy i znaleźć inną pomoc, zapoznaj się z przewodnikiem pomocy dotyczącym Osób w wersji 1.

Przykładowy kod

W przykładowym kodzie poniżej użyto wersji 1 interfejsu API.

Pobieranie połączeń użytkownika

Aby pobrać listę osób z kontaktów użytkownika, użyj tego kodu:

zaawansowane/osoby.gs
/**
 * Gets a list of people in the user's contacts.
 * @see https://developers.google.com/people/api/rest/v1/people.connections/list
 */
function getConnections() {
  try {
    // Get the list of connections/contacts of user's profile
    const people = 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);
  }
}

Pobierz informacje o osobie dla użytkownika

Aby pobrać profil użytkownika, musisz zażądać zakresu https://www.googleapis.com/auth/userinfo.profile, wykonując instrukcje dodawania jawnych zakresów do pliku manifestu appsscript.json. Po dodaniu zakresu możesz użyć tego kodu:

zaawansowane/osoby.gs
/**
 * Gets the own user's profile.
 * @see https://developers.google.com/people/api/rest/v1/people/getBatchGet
 */
function getSelf() {
  try {
    // Get own user's profile using People.getBatchGet() method
    const people = 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);
  }
}

Znajdź osobę, która założy konto Google

Aby pobrać informacje o osobie z dowolnego konta Google, użyj tego kodu:

zaawansowane/osoby.gs
/**
 * 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
 */
function getAccount(accountId) {
  try {
    // Get the Account details using account ID.
    const people = 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);
  }
}