पढ़ें, कॉपी करें, और खोजें "अन्य संपर्क"

People API का इस्तेमाल करने के लिए तैयारी करना में दिया गया तरीका पूरा करने के बाद, "अन्य संपर्क" डेटा को पढ़ा, कॉपी, और खोजा जा सकता है.

नीचे दिए गए कोड सैंपल में, कुछ आसान अनुरोध भेजने का तरीका बताया गया है. तरीकों की पूरी सूची के लिए, रेफ़रंस दस्तावेज़ देखें.

उपयोगकर्ता के "अन्य संपर्क" की सूची बनाना

उपयोगकर्ता के "अन्य संपर्क" में मौजूद लोगों की सूची पाने के लिए, यहां दिया गया कोड इस्तेमाल करें:

प्रोटोकॉलJava
GET /v1/otherContacts?readMask=names,emailAddresses HTTP/1.1
Host: people.googleapis.com
ListOtherContactsResponse response = peopleService.otherContacts().list()
   
.setReadMask("metadata,names,emailAddresses")
   
.execute();

List<Person> otherContacts = response.getOtherContacts();

उपयोगकर्ता के उन "अन्य संपर्कों" की सूची जिनमें बदलाव हुआ है

Java
// Initial request
ListOtherContactsResponse fullSyncResponse = peopleService.otherContacts().list()
   
.setReadMask("metadata,names,emailAddresses")
   
.setRequestSyncToken(true)
   
.execute();
// Fetch all the pages
while (fullSyncResponse.getNextPageToken() != null) {
  fullSyncResponse
= peopleService.otherContacts().list()
     
.setReadMask("metadata,names,emailAddresses")
     
.setRequestSyncToken(true)
     
.setPageToken(fullSyncResponse.getNextPageToken())
     
.execute();
}

// Some time passes

// Fetch incremental changes using the sync token returned in the last fullSyncResponse.
try {
 
ListOtherContactsResponse incrementalSyncResponse = peopleService.otherContacts().list()
     
.setReadMask("metadata,names,emailAddresses")
     
.setSyncToken(fullSyncResponse.getNextSyncToken())
     
.execute();
 
for (Person person : incrementalSyncResponse.getOtherContacts()) {
    handlePerson
(person);
 
}
 
 
// Fetch all the pages
 
while (!incrementalSyncResponse.getNextPageToken().isEmpty()) {
    incrementalSyncResponse
= peopleService.otherContacts().list()
       
.setReadMask("metadata,names,emailAddresses")
       
.setSyncToken(fullSyncResponse.getNextSyncToken())
       
.setPageToken(incrementalSyncResponse.getNextPageToken())
       
.execute();
   
for (Person person : incrementalSyncResponse.getOtherContacts()) {
      handlePerson
(person);
   
}
 
}
} catch (GoogleJsonResponseException e) {
 
if (e.getStatusCode() == 410) {
   
// Sync token expired. Make full sync request.
 
}
}

void handlePerson(Person person) {
 
if (person.getMetadata().getDeleted()) {
   
// Handle deleted person
 
} else {
   
// Handle changed person
 
}
}

सिंक करने के व्यवहार के बारे में ज़्यादा जानकारी के लिए, ListOtherContacts पर जाएं.

"अन्य संपर्क" को "myContacts" ग्रुप में कॉपी करना

"अन्य संपर्क" को "myContacts" ग्रुप में कॉपी करने के लिए, नीचे दिए गए कोड का इस्तेमाल करें:

प्रोटोकॉलJava
POST /v1/resource_name:copyOtherContactToMyContactsGroup?copyMask=names,emailAddresses,phoneNumbers HTTP/1.1
Host: people.googleapis.com
Person copiedContact = peopleService
   
.otherContacts()
   
.copyOtherContactToMyContactsGroup(
       
"resource_name",
       
new CopyOtherContactToMyContactsGroupRequest()
           
.setCopyMask("names,emailAddresses,phoneNumbers"))
   
.execute();

उपयोगकर्ता के "अन्य संपर्क" खोजना

उपयोगकर्ता के सभी "अन्य संपर्क" खोजने के लिए, यहां दिए गए कोड का इस्तेमाल करें:

प्रोटोकॉलJava
// Warmup cache
GET
/v1/otherContacts:search?query=&readMask=names,emailAddresses HTTP/1.1
Host: people.googleapis.com

// Send search request after several seconds
GET
/v1/otherContacts:search?query=query&readMask=names,emailAddresses HTTP/1.1
Host: people.googleapis.com
// Warmup cache
SearchResponse response = peopleService.otherContacts().search()
   
.setQuery("")
   
.setReadMask("names,emailAddresses")
   
.execute();

// Wait a few seconds
Thread.sleep(5);

// Send search request
SearchResponse response = peopleService.otherContacts().search()
   
.setQuery("query")
   
.setReadMask("names,emailAddresses")
   
.execute();