خدمات افراد پیشرفته

سرویس پیشرفته People به شما امکان می دهد از People API در Apps Script استفاده کنید. این API به اسکریپت‌ها اجازه می‌دهد تا داده‌های تماس را برای کاربر وارد شده ایجاد، خواندن و به‌روزرسانی کنند و داده‌های نمایه را برای کاربران Google بخوانند.

ارجاع

برای اطلاعات دقیق در مورد این سرویس، به مستندات مرجع برای People API مراجعه کنید. مانند همه سرویس‌های پیشرفته در Apps Script، سرویس پیشرفته افراد از همان اشیا، روش‌ها و پارامترهای API عمومی استفاده می‌کند. برای اطلاعات بیشتر، نحوه تعیین امضای روش را ببینید.

برای گزارش مشکلات و یافتن پشتیبانی دیگر، راهنمای پشتیبانی People v1 را ببینید.

کد نمونه

کد نمونه زیر از نسخه 1 API استفاده می کند.

اتصالات کاربر را دریافت کنید

برای دریافت لیستی از افراد در مخاطبین کاربر ، از کد زیر استفاده کنید:

/**
 * 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 خود درخواست کنید. پس از اضافه شدن دامنه، می توانید از کد زیر استفاده کنید:

/**
 * 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 ، از کد زیر استفاده کنید:

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