고급 사용자 서비스

고급 피플 서비스를 사용하면 Apps Script에서 People API를 사용할 수 있습니다. 이 API를 사용하면 스크립트에서 로그인한 사용자의 연락처 데이터를 만들고 읽고 업데이트하고 Google 사용자의 프로필 데이터를 읽을 수 있습니다.

참조

이 서비스에 대한 자세한 내용은 People API의 참조 문서를 확인하세요. Apps Script의 모든 고급 서비스와 마찬가지로 고급 사용자 서비스는 공개 API와 동일한 객체, 메서드, 매개변수를 사용합니다. 자세한 내용은 메서드 서명 확인 방법을 참조하세요.

문제를 신고하고 다른 지원을 받으려면 사용자 v1 지원 가이드를 참조하세요.

샘플 코드

아래 샘플 코드는 API의 버전 1을 사용합니다.

사용자의 연결 가져오기

사용자의 연락처에 있는 사용자 목록을 가져오려면 다음 코드를 사용합니다.

Advanced/people.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);
  }
}

사용자를 대신해 사용자 가져오기

사용자의 프로필을 가져오려면 appsscript.json 매니페스트 파일에 명시적인 범위를 추가하는 방법에 따라 https://www.googleapis.com/auth/userinfo.profile 범위를 요청해야 합니다. 범위가 추가되면 다음 코드를 사용할 수 있습니다.

Advanced/people.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);
  }
}

Google 계정에 등록된 사용자 가져오기

Google 계정의 개인 정보를 가져오려면 다음 코드를 사용합니다.

Advanced/people.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);
  }
}