Google Apps Script 빠른 시작

People API에 요청을 보내는 Google Apps Script 를 만듭니다.

빠른 시작에서는 Google Workspace API를 호출하는 앱을 설정하고 실행하는 방법을 설명합니다. 이 빠른 시작에서는 테스트 환경에 적합한 간소화된 인증 접근 방식을 사용합니다. 프로덕션 환경의 경우 앱에 적합한 액세스 사용자 인증 정보를 선택하기 전에 인증 및 승인 에 대해 알아보는 것이 좋습니다.

Apps Script에서 Google Workspace 빠른 시작은 고급 Google 서비스를 사용하여 Google Workspace API를 호출하고 인증 및 승인 흐름의 일부 세부정보를 처리합니다.

목표

  • 환경 구성
  • 스크립트를 만들고 구성합니다.
  • 스크립트를 실행합니다.

기본 요건

  • Google Drive 액세스

스크립트 만들기

  1. script.google.com/create로 이동하여 Apps Script 편집기에서 새 스크립트를 만듭니다.
  2. 스크립트 편집기의 내용을 다음 코드로 바꿉니다.

people/quickstart/quickstart.gs
/**
 * @typedef {Object} EmailAddress
 * @see https://developers.google.com/people/api/rest/v1/people#Person
 * @property {string} value
 * Note: This is a partial definition.
 */

/**
 * @typedef {Object} Name
 * @see https://developers.google.com/people/api/rest/v1/people#Person
 * @property {string} displayName
 * Note: This is a partial definition.
 */

/**
 * @typedef {Object} Person
 * @see https://developers.google.com/people/api/rest/v1/people#Person
 * @property {Name[]} names
 * @property {EmailAddress[]} [emailAddresses]
 * Note: This is a partial definition.
 */

/**
 * @typedef {Object} Connection
 * @see https://developers.google.com/people/api/rest/v1/people.connections/list
 * @property {Person[]} connections
 * Note: This is a partial definition.
 */

/**
 * Print the display name if available for 10 connections.
 */
function listConnectionNames() {
  // Use the People API to list the connections of the logged in user.
  // See: https://developers.google.com/people/api/rest/v1/people.connections/list
  if (!People || !People.People || !People.People.Connections) {
    throw new Error("People service not enabled.");
  }
  const connections = People.People.Connections.list("people/me", {
    pageSize: 10,
    personFields: "names,emailAddresses",
  });
  if (!connections.connections) {
    console.log("No connections found.");
    return;
  }
  for (const person of connections.connections) {
    if (
      person.names &&
      person.names.length > 0 &&
      person.names[0].displayName
    ) {
      console.log(person.names[0].displayName);
    } else {
      console.log("No display name found for connection.");
    }
  }
}

  1. 저장 을 클릭합니다.
  2. 제목 없는 프로젝트를 클릭하고 빠른 시작을 입력한 다음 이름 바꾸기를 클릭합니다.

스크립트 구성

People API 사용 설정

Apps Script 프로젝트를 엽니다.

  1. 편집기 를 클릭합니다.
  2. 서비스 옆에 있는 서비스 추가 를 클릭합니다 .
  3. People API를 선택하고 추가를 클릭합니다.

샘플 실행

Apps Script 편집기에서 실행 을 클릭합니다.

샘플을 처음 실행하면 액세스 권한을 부여하라는 메시지가 표시됩니다.

  1. 권한 검토 를 클릭합니다.
  2. 계정을 선택합니다.
  3. 허용 을 클릭합니다.

스크립트의 실행 로그가 창 하단에 표시됩니다.

다음 단계