خدمة الأشخاص المتقدمة

تسمح لك خدمة "الأشخاص" المتقدمة باستخدام People API في "برمجة تطبيقات Google". تسمح واجهة برمجة التطبيقات هذه للنصوص البرمجية بإنشاء وقراءة وتحديث بيانات الاتصال للمستخدم الذي سجّل الدخول، بالإضافة إلى قراءة بيانات الملف الشخصي لمستخدمي Google.

مَراجع

للحصول على معلومات مفصّلة حول هذه الخدمة، يُرجى الاطّلاع على المستندات المرجعية الخاصة بواجهة People API. مثل جميع الخدمات المتقدمة في برمجة التطبيقات، تستخدم خدمة "الأشخاص" المتقدمة نفس العناصر والطرق والمعلمات مثل واجهة برمجة التطبيقات العامة. لمزيد من المعلومات، يُرجى الاطِّلاع على كيفية تحديد توقيعات الطرق.

للإبلاغ عن المشاكل والعثور على خدمات دعم أخرى، يمكنك الاطّلاع على دليل الدعم للإصدار الأول من المستخدمين.

نموذج التعليمات البرمجية

يستخدم الرمز النموذجي أدناه الإصدار 1 من واجهة برمجة التطبيقات.

الحصول على اتصالات المستخدم

للحصول على قائمة بالأشخاص في جهات اتصال المستخدم، استخدِم الرمز التالي:

متقدم/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);
  }
}

الحصول على الشخص للمستخدم

للحصول على الملف الشخصي للمستخدم، يجب طلب نطاق https://www.googleapis.com/auth/userinfo.profile من خلال اتّباع تعليمات إضافة نطاقات صريحة إلى ملف بيان appsscript.json. بمجرد إضافة النطاق، يمكنك استخدام التعليمة البرمجية التالية:

متقدم/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، استخدِم الرمز التالي:

متقدم/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);
  }
}