고급 사용자 서비스

Apps Script 내 Google 사용자의 데이터입니다.

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

이 서비스는 고급 서비스로, 사용하기 전에 사용 설정해야 합니다 .

참조

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

문제를 신고하고 기타 지원을 받으려면 People 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);
  }
}

사용자의 사용자 가져오기

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

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);
  }
}