Layanan Orang Lanjutan

Dengan layanan People lanjutan, Anda dapat menggunakan People API di Apps Script. API ini memungkinkan skrip membuat, membaca, dan memperbarui data kontak untuk pengguna yang login dan membaca data profil untuk pengguna Google.

Referensi

Untuk mendapatkan informasi mendetail tentang layanan ini, lihat dokumentasi referensi untuk People API. Seperti semua layanan lanjutan di Apps Script, layanan People lanjutan menggunakan objek, metode, dan parameter yang sama dengan API publik. Untuk informasi selengkapnya, lihat Cara tanda tangan metode ditentukan.

Untuk melaporkan masalah dan menemukan dukungan lain, lihat Panduan dukungan People v1.

Kode contoh

Kode contoh di bawah menggunakan API versi 1.

Mengetahui koneksi pengguna

Untuk mendapatkan daftar orang di kontak pengguna, gunakan kode berikut:

{i>advanced/people.gs<i}
/**
 * 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);
  }
}

Mendapatkan orang untuk pengguna

Untuk mendapatkan profil pengguna, Anda perlu meminta cakupan https://www.googleapis.com/auth/userinfo.profile dengan mengikuti petunjuk untuk menambahkan cakupan eksplisit ke file manifes appsscript.json. Setelah cakupan ditambahkan, Anda dapat menggunakan kode berikut:

{i>advanced/people.gs<i}
/**
 * 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);
  }
}

Dapatkan orang tersebut untuk mendapatkan Akun Google

Guna mendapatkan informasi orang tersebut untuk Akun Google apa pun, gunakan kode berikut:

{i>advanced/people.gs<i}
/**
 * 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);
  }
}