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

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

रेफ़रंस

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

समस्याओं की शिकायत करने और मदद पाने के लिए, 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);
  }
}