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

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

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

ऐसे तरीके जिनके लिए People API के बराबर कोई तरीका उपलब्ध नहीं है

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

ऐसे तरीके जिनके बराबर कोई दूसरा तरीका नहीं है
  • 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 पैरामीटर का इस्तेमाल किया जाता है. मिलते-जुलते फ़ील्ड के हिसाब से संपर्क पाने के लिए, People API की ऐडवांस सेवा में searchContacts का इस्तेमाल किया जा सकता है. हालांकि, खोज को किसी खास लेबल तक सीमित नहीं किया जा सकता.

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

People API की अन्य सुविधाएं

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

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

इस सेक्शन में, संपर्कों की सेवा से जुड़े सामान्य टास्क की सूची दी गई है. कोड के सैंपल में, People API की बेहतर सेवा का इस्तेमाल करके टास्क बनाने का तरीका बताया गया है.

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

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

advanced/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) का इस्तेमाल करने जैसा ही है.

advanced/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);
  }
}

सभी संपर्कों की जानकारी पाना

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

advanced/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() के बराबर होता है.

advanced/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);
  }
}

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

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

advanced/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);
  }
}

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

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

advanced/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);
  }
}