// Initial requestListOtherContactsResponsefullSyncResponse=peopleService.otherContacts().list().setReadMask("metadata,names,emailAddresses").setRequestSyncToken(true).execute();// Fetch all the pageswhile(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{ListOtherContactsResponseincrementalSyncResponse=peopleService.otherContacts().list().setReadMask("metadata,names,emailAddresses").setSyncToken(fullSyncResponse.getNextSyncToken()).execute();for(Personperson:incrementalSyncResponse.getOtherContacts()){handlePerson(person);}// Fetch all the pageswhile(!incrementalSyncResponse.getNextPageToken().isEmpty()){incrementalSyncResponse=peopleService.otherContacts().list().setReadMask("metadata,names,emailAddresses").setSyncToken(fullSyncResponse.getNextSyncToken()).setPageToken(incrementalSyncResponse.getNextPageToken()).execute();for(Personperson:incrementalSyncResponse.getOtherContacts()){handlePerson(person);}}}catch(GoogleJsonResponseExceptione){if(e.getStatusCode()==410){// Sync token expired. Make full sync request.}}voidhandlePerson(Personperson){if(person.getMetadata().getDeleted()){// Handle deleted person}else{// Handle changed person}}
// Warmup cacheGET/v1/otherContacts:search?query=&readMask=names,emailAddressesHTTP/1.1Host:people.googleapis.com// Send search request after several secondsGET/v1/otherContacts:search?query=query&readMask=names,emailAddressesHTTP/1.1Host:people.googleapis.com
Java
// Warmup cacheSearchResponseresponse=peopleService.otherContacts().search().setQuery("").setReadMask("names,emailAddresses").execute();// Wait a few secondsThread.sleep(5);// Send search requestSearchResponseresponse=peopleService.otherContacts().search().setQuery("query").setReadMask("names,emailAddresses").execute();
[null,null,["最后更新时间 (UTC):2025-08-29。"],[[["\u003cp\u003eThis guide demonstrates how to use the People API to interact with a user's "Other contacts" data after completing the initial setup.\u003c/p\u003e\n"],["\u003cp\u003eYou can retrieve a list of contacts, including changes since the last sync, and copy them to the "myContacts" group.\u003c/p\u003e\n"],["\u003cp\u003eThe API also enables searching within "Other contacts" but requires an initial warmup request for optimal results.\u003c/p\u003e\n"],["\u003cp\u003eJava code snippets and HTTP request examples are provided for each function, making integration easier.\u003c/p\u003e\n"]]],["The document details actions for interacting with \"Other contacts\" data via the People API. Key actions include: listing all or changed \"Other contacts\" by using `list` method with optional sync tokens. Copying an \"Other contact\" to the \"myContacts\" group is done using the `copyOtherContactToMyContactsGroup` method. Finally, searching \"Other contacts\" involves a warmup request with an empty query, followed by the actual search request using the `search` method and prefix matching.\n"],null,["# Read, Copy, and Search "Other contacts"\n\n\u003cbr /\u003e\n\nAfter you've completed the steps in [Get Ready to Use the People API](/people/v1/getting-started), you are ready to read, copy, and search \"Other contacts\" data.\n\nThe following code samples demonstrate how to send a few simple requests. For a full list of methods, see the [reference documentation](/people/api/rest).\n\nList the user's \"Other contacts\"\n--------------------------------\n\nTo\n[get a list of people in the user's \"Other contacts\"](/people/api/rest/v1/otherContacts/list),\nuse the following code: \n\n### Protocol\n\n```http\nGET /v1/otherContacts?readMask=names,emailAddresses HTTP/1.1\nHost: people.googleapis.com\n```\n\n### Java\n\n```java\nListOtherContactsResponse response = peopleService.otherContacts().list()\n .setReadMask(\"metadata,names,emailAddresses\")\n .execute();\n\nList\u003cPerson\u003e otherContacts = response.getOtherContacts();\n```\n\nList the user's \"Other contacts\" that have changed\n--------------------------------------------------\n\n### Java\n\n```java\n// Initial request\nListOtherContactsResponse fullSyncResponse = peopleService.otherContacts().list()\n .setReadMask(\"metadata,names,emailAddresses\")\n .setRequestSyncToken(true)\n .execute();\n// Fetch all the pages\nwhile (fullSyncResponse.getNextPageToken() != null) {\n fullSyncResponse = peopleService.otherContacts().list()\n .setReadMask(\"metadata,names,emailAddresses\")\n .setRequestSyncToken(true)\n .setPageToken(fullSyncResponse.getNextPageToken())\n .execute();\n}\n\n// Some time passes\n\n// Fetch incremental changes using the sync token returned in the last fullSyncResponse.\ntry {\n ListOtherContactsResponse incrementalSyncResponse = peopleService.otherContacts().list()\n .setReadMask(\"metadata,names,emailAddresses\")\n .setSyncToken(fullSyncResponse.getNextSyncToken())\n .execute();\n for (Person person : incrementalSyncResponse.getOtherContacts()) {\n handlePerson(person);\n }\n \n // Fetch all the pages\n while (!incrementalSyncResponse.getNextPageToken().isEmpty()) {\n incrementalSyncResponse = peopleService.otherContacts().list()\n .setReadMask(\"metadata,names,emailAddresses\")\n .setSyncToken(fullSyncResponse.getNextSyncToken())\n .setPageToken(incrementalSyncResponse.getNextPageToken())\n .execute();\n for (Person person : incrementalSyncResponse.getOtherContacts()) {\n handlePerson(person);\n }\n }\n} catch (GoogleJsonResponseException e) {\n if (e.getStatusCode() == 410) {\n // Sync token expired. Make full sync request.\n }\n}\n\nvoid handlePerson(Person person) {\n if (person.getMetadata().getDeleted()) {\n // Handle deleted person\n } else {\n // Handle changed person\n }\n}\n```\n| **Note:** Writes may have a propagation delay of several minutes for sync requests. Incremental syncs are not intended for read-after-write use cases.\n\nMore details about sync behavior at [ListOtherContacts](/people/api/rest/v1/otherContacts/list).\n\nCopy an \"Other contact\" to \"myContacts\" group\n---------------------------------------------\n\nTo\n[copy an \"Other contact\" to \"myContacts\" group](/people/api/rest/v1/otherContacts/copyOtherContactToMyContactsGroup),\nuse the following code: \n\n### Protocol\n\n```http\nPOST /v1/\u003cvar translate=\"no\"\u003eresource_name\u003c/var\u003e:copyOtherContactToMyContactsGroup?copyMask=names,emailAddresses,phoneNumbers HTTP/1.1\nHost: people.googleapis.com\n```\n\n### Java\n\n```java\nPerson copiedContact = peopleService\n .otherContacts()\n .copyOtherContactToMyContactsGroup(\n \"\u003cvar translate=\"no\"\u003eresource_name\u003c/var\u003e\",\n new CopyOtherContactToMyContactsGroupRequest()\n .setCopyMask(\"names,emailAddresses,phoneNumbers\"))\n .execute();\n```\n\nSearch the user's \"Other contacts\"\n----------------------------------\n\nTo\n[search all of the user's \"Other contacts\"](/people/api/rest/v1/otherContacts/search),\nuse the following code: \n\n### Protocol\n\n```scilab\n// Warmup cache\nGET /v1/otherContacts:search?query=&readMask=names,emailAddresses HTTP/1.1\nHost: people.googleapis.com\n\n// Send search request after several seconds\nGET /v1/otherContacts:search?query=query&readMask=names,emailAddresses HTTP/1.1\nHost: people.googleapis.com\n```\n\n### Java\n\n```java\n// Warmup cache\nSearchResponse response = peopleService.otherContacts().search()\n .setQuery(\"\")\n .setReadMask(\"names,emailAddresses\")\n .execute();\n\n// Wait a few seconds\nThread.sleep(5);\n\n// Send search request\nSearchResponse response = peopleService.otherContacts().search()\n .setQuery(\"\u003cvar translate=\"no\"\u003equery\u003c/var\u003e\")\n .setReadMask(\"names,emailAddresses\")\n .execute();\n```\n| **Important:** Search uses a lazy cache that is updated after a request. Clients should first send a warmup search request with an empty query to make sure the cache has the latest data.\n| **Note:** Search does a prefix match of the query with the fields on a person. For example, a person with name \"foo name\" matches queries such as \"f\", \"fo\", \"foo\", \"foo n\", \"nam\", etc., but not \"oo n\"."]]