高度な人事サービス

高度な People サービスでは、Apps Script で People API を使用できます。この API を使用すると、スクリプトでログイン ユーザーの連絡先データの作成、読み取り、更新と、Google ユーザーのプロファイル データの読み取りを行うことができます。

リファレンス

このサービスの詳細については、People API のリファレンス ドキュメントをご覧ください。Apps Script のすべての高度なサービスと同様に、高度な People サービスでも公開 API と同じオブジェクト、メソッド、パラメータを使用します。詳細については、メソッド シグネチャの決定方法をご覧ください。

問題を報告し、他のサポートを確認するには、People v1 のサポートガイドをご覧ください。

サンプルコード

以下のサンプルコードでは、バージョン 1 の API を使用しています。

ユーザーの接続を取得する

ユーザーの連絡先に登録されているユーザーのリストを取得するには、次のコードを使用します。

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