Contacts सेवा से People API की बेहतर सेवा पर माइग्रेट करना

अहम जानकारी: मार्च 2023 में Apps Script के बंद होने से पहले, Contacts की जानकारी को Contacts सेवा से People API की बेहतर सेवा पर माइग्रेट करें.

Apps Script ने 16 दिसंबर,2022 को Contacts सेवा को बंद कर दिया है. इसके बजाय, People API की बेहतर सेवा का इस्तेमाल करें. लोगों का एपीआई एक नए JSON प्रोटोकॉल का इस्तेमाल करता है और बेहतर सुविधाएं देता है, जैसे कि संपर्कों को प्रोफ़ाइलों के साथ मर्ज करना.

इस गाइड का इस्तेमाल करके जानें कि People API की बेहतर सेवा में, Contacts सेवा के कौनसे तरीके काम नहीं करते. साथ ही, जानें कि इसके बजाय आप क्या इस्तेमाल कर सकते हैं और सामान्य टास्क को माइग्रेट करने के लिए कोड सैंपल ढूंढें. ज़्यादा जानकारी के लिए, Contacts API माइग्रेशन गाइड देखें.

ऐसे तरीके जिनमें पीपल एपीआई की सुविधा उपलब्ध नहीं है

यहां Contacts सेवा में getContacts के ऐसे तरीकों के बारे में बताया गया है जिनके लिएPeople API की बेहतर सेवा में संपर्कों को खोजने के समान तरीके नहीं दिए गए हैं. लोगों के एपीआई की बेहतर सेवा की मदद से, किसी संपर्क के names, nickNames, emailAddresses, phoneNumbers, और organizations फ़ील्ड की मदद से खोजा जा सकता है. यह जानकारी CONTACT सोर्स के होती है.

मिलते-जुलते नतीजे न दिखाने वाले तरीके
  • getContactsByAddress(query)
  • getContactsByAddress(query, label)
  • getContactsByAddress(query, label)
  • getContactsByCustomField(query, label)
  • getContactsByDate(month, day, label)
  • getContactsByDate(month, day, year, label)
  • getContactsByDate(month, day, year, label)
  • getContactsByIM(query)
  • getContactsByIM(query, label)
  • getContactsByJobTitle(query)
  • getContactsByNotes(query)
  • getContactsByUrl(query)
  • getContactsByUrl(query, label)
  • getContactsByGroup(group)

यहां Contacts सेवा के उन getContacts तरीकों की सूची दी गई है जो अतिरिक्त label पैरामीटर का इस्तेमाल करते हैं. मिलते-जुलते फ़ील्ड के हिसाब से संपर्क पाने के लिए, लोगों के एपीआई की बेहतर सेवा की मदद से searchContacts का इस्तेमाल किया जा सकता है. हालांकि, खोज को किसी खास लेबल तक सीमित नहीं किया जा सकता.

कुछ हद तक मिलते-जुलते तरीकों वाले तरीके
  • getContactsByEmailAddress(query, label)
  • getContactsByName(query, label)
  • getContactsByPhone(query, label)

लोगों के एपीआई में उपलब्ध अन्य सुविधाएं

लोगों के एपीआई की बेहतर सेवा पर माइग्रेट करने पर, आप पीपल API की ये सुविधाएं ऐक्सेस कर सकते हैं जो संपर्क सेवा में उपलब्ध नहीं हैं:

सामान्य कामों के लिए कोड सैंपल

इस सेक्शन में Contacts सेवा के सामान्य टास्क की सूची होती है. कोड सैंपल दिखाते हैं कि लोग API की बेहतर सेवा का इस्तेमाल करके, टास्क कैसे बनाए जाएं.

नाम के हिसाब से संपर्क ग्रुप पाएं

नीचे दिया गया कोड सैंपल दिखाता है कि किसी संपर्क ग्रुप को उसके नाम से कैसे खोजा जा सकता है. यह संपर्क सेवा में getContactGroup(name) की तरह ही है.

ऐडवांस/people.gs
/**
 * Gets a contact group with the given name
 * @param {string} name The group name.
 * @see https://developers.google.com/people/api/rest/v1/contactGroups/list
 */
function getContactGroup(name) {
  try {
    const people = People.ContactGroups.list();
    // Finds the contact group for the person where the name matches.
    const group = people['contactGroups'].find((group) => group['name'] === name);
    // Prints the contact group
    console.log('Group: %s', JSON.stringify(group, null, 2));
  } catch (err) {
    // TODO (developers) - Handle exception
    console.log('Failed to get the contact group with an error %s', err.message);
  }
}

ईमेल पते से संपर्क पाएं

नीचे दिया गया कोड सैंपल दिखाता है कि किसी संपर्क को उसके ईमेल पते से कैसे पाया जाए. यह ईमेल पता, Contacts सेवा में getContact(emailAddress) के बराबर है.

ऐडवांस/people.gs
/**
 * Gets a contact by the email address.
 * @param {string} email The email address.
 * @see https://developers.google.com/people/api/rest/v1/people.connections/list
 */
function getContactByEmail(email) {
  try {
    // Gets the person with that email address by iterating over all contacts.
    const people = People.People.Connections.list('people/me', {
      personFields: 'names,emailAddresses'
    });
    const contact = people['connections'].find((connection) => {
      return connection['emailAddresses'].some((emailAddress) => emailAddress['value'] === email);
    });
    // Prints the contact.
    console.log('Contact: %s', JSON.stringify(contact, null, 2));
  } catch (err) {
    // TODO (developers) - Handle exception
    console.log('Failed to get the connection with an error %s', err.message);
  }
}

सभी संपर्क पाएं

नीचे दिए गए कोड सैंपल में बताया गया है कि किसी उपयोगकर्ता के सभी संपर्क कैसे पाए जा सकते हैं, जो संपर्क सेवा में getContacts() के बराबर है.

ऐडवांस/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);
  }
}

संपर्क का पूरा नाम जानें

नीचे दिए गए कोड सैंपल में, संपर्क का पूरा नाम पाने का तरीका बताया गया है. यह नाम, Contacts सेवा में getFullName() के बराबर है.

ऐडवांस/people.gs
/**
 * Gets the full name (given name and last name) of the contact as a string.
 * @see https://developers.google.com/people/api/rest/v1/people/get
 */
function getFullName() {
  try {
    // Gets the person by specifying resource name/account ID
    // in the first parameter of People.People.get.
    // This example gets the person for the user running the script.
    const people = People.People.get('people/me', {personFields: 'names'});
    // Prints the full name (given name + family name)
    console.log(`${people['names'][0]['givenName']} ${people['names'][0]['familyName']}`);
  } catch (err) {
    // TODO (developers) - Handle exception
    console.log('Failed to get the connection with an error %s', err.message);
  }
}

किसी संपर्क के सभी फ़ोन नंबर पाएं

नीचे दिए गए कोड सैंपल में बताया गया है कि किसी संपर्क के सभी फ़ोन नंबर कैसे पाए जा सकते हैं. यह तरीका संपर्क सेवा में getPhones() की तरह ही है.

ऐडवांस/people.gs
/**
 * Gets all the phone numbers for this contact.
 * @see https://developers.google.com/people/api/rest/v1/people/get
 */
function getPhoneNumbers() {
  try {
    // Gets the person by specifying resource name/account ID
    // in the first parameter of People.People.get.
    // This example gets the person for the user running the script.
    const people = People.People.get('people/me', {personFields: 'phoneNumbers'});
    // Prints the phone numbers.
    console.log(people['phoneNumbers']);
  } catch (err) {
    // TODO (developers) - Handle exception
    console.log('Failed to get the connection with an error %s', err.message);
  }
}

किसी संपर्क के लिए कोई खास फ़ोन नंबर पाएं

नीचे दिए गए कोड सैंपल में बताया गया है कि किसी संपर्क के लिए कोई खास फ़ोन नंबर कैसे पाया जाए. यह नंबर संपर्क सेवा में getPhoneNumber() की तरह ही होता है.

ऐडवांस/people.gs
/**
 * Gets a phone number by type, such as work or home.
 * @see https://developers.google.com/people/api/rest/v1/people/get
 */
function getPhone() {
  try {
    // Gets the person by specifying resource name/account ID
    // in the first parameter of People.People.get.
    // This example gets the person for the user running the script.
    const people = People.People.get('people/me', {personFields: 'phoneNumbers'});
    // Gets phone number by type, such as home or work.
    const phoneNumber = people['phoneNumbers'].find((phone) => phone['type'] === 'home')['value'];
    // Prints the phone numbers.
    console.log(phoneNumber);
  } catch (err) {
    // TODO (developers) - Handle exception
    console.log('Failed to get the connection with an error %s', err.message);
  }
}