Read, Copy, and Search "Other contacts"

After you've completed the steps in Get Ready to Use the People API, you are ready to read, copy, and search "Other contacts" data.

The following code samples demonstrate how to send a few simple requests:

  • List the user's "Other contacts".
  • Copy an "Other contact" to "myContacts" group.
  • Search the user's "Other contacts".

For a full list of methods, see the reference documentation.

List the user's "Other contacts"

To get a list of people in the user's "Other contacts", use the following code:

Protocol

GET /v1/otherContacts?readMask=names,emailAddresses HTTP/1.1
Host: people.googleapis.com

Java

ListOtherContactsResponse response = peopleService.otherContacts().list()
    .setReadMask("metadata,names,emailAddresses")
    .execute();

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

Copy an "Other contact" to "myContacts" group

To copy an "Other contact" to "myContacts" group, use the following code:

Protocol

POST /v1/resource_name:copyOtherContactToMyContactsGroup?copyMask=names,emailAddresses,phoneNumbers HTTP/1.1
Host: people.googleapis.com

Java

Person copiedContact = peopleService
    .otherContacts()
    .copyOtherContactToMyContactsGroup(
        "resource_name",
        new CopyOtherContactToMyContactsGroupRequest()
            .setCopyMask("names,emailAddresses,phoneNumbers"))
    .execute();

Search the user's "Other contacts"

To search all of the user's "Other contacts", use the following code:

Protocol

GET /v1/otherContacts:search?query=query&readMask=names,emailAddresses HTTP/1.1
Host: people.googleapis.com

Java

SearchResponse response = peopleService.otherContacts().search()
    .setQuery("query")
    .setReadMask("names,emailAddresses")
    .execute();
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". "Other contacts" are only matched by their names, emailAddresses, and phoneNumbers.