लोगों से जुड़ी बेहतर सेवा

बेहतर लोगों की सेवा से, आपको Apps Script में People API का इस्तेमाल करने की सुविधा मिलती है. यह एपीआई, स्क्रिप्ट को लॉग इन किए हुए उपयोगकर्ता के लिए संपर्क डेटा बनाने, पढ़ने, और अपडेट करने की अनुमति देता है. साथ ही, Google उपयोगकर्ताओं का प्रोफ़ाइल डेटा पढ़ने में भी मदद करता है.

रेफ़रंस

इस सेवा के बारे में ज़्यादा जानकारी के लिए, लोगों एपीआई के रेफ़रंस दस्तावेज़ देखें. Apps Script की सभी बेहतर सेवाओं की तरह, लोगों की बेहतर सेवा में भी उन ही ऑब्जेक्ट, तरीकों, और पैरामीटर का इस्तेमाल किया जाता है जो सार्वजनिक एपीआई में हैं. ज़्यादा जानकारी के लिए, हस्ताक्षर तय करने का तरीका लेख पढ़ें.

समस्याओं की शिकायत करने और अन्य मदद पाने के लिए, People v1 की सहायता गाइड देखें.

नमूना कोड

नीचे दिए गए सैंपल कोड में, एपीआई के वर्शन 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);
  }
}

उपयोगकर्ता को ऐक्सेस देने के लिए

उपयोगकर्ता की प्रोफ़ाइल पाने के लिए, आपको 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);
  }
}

उस व्यक्ति से 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);
  }
}