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

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

مرجع

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

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

کد نمونه

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

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

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

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

پیشرفته/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);
  }
}

دریافت شخص برای حساب گوگل

برای دریافت اطلاعات شخص برای هر حساب گوگل ، از کد زیر استفاده کنید:

پیشرفته/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);
  }
}