Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

People API of google versus contacts API

Tags:

While trying to fetch contacts using google account of user , I am facing some issues after using people API.It only returns few email addresses out of all listed ones.Access token and all scopes have been set correctly. Code for following :

People peopleService = new People.Builder(httpTransport, jsonFactory, credential)
                    .build();
ListConnectionsResponse response = peopleService.people().connections().list("people/me")
                    .setPageSize(500).setSortOrder("FIRST_NAME_ASCENDING")
                    .setAccessToken(tokenResponse.getAccessToken())
                    .setAlt("json")
                    .setRequestMaskIncludeField("person.names,person.emailAddresses,person.phoneNumbers")
                    . execute();
   connections = response.getConnections();

Instead of this if I use contact API of google then I am getting more no of email addresses than people.Code for contact API :

URL feedUrl = new URL("https://www.google.com/m8/feeds/contacts/default/full");
    ContactFeed resultFeed = myService.getFeed(feedUrl, ContactFeed.class);

    // Print the results
    System.out.println(resultFeed.getTitle().getPlainText());
    for (ContactEntry entry : resultFeed.getEntries()) {
          ....
          .....
          .......
 }

I want to know if there is any difference between both of them and which one i have to use for better results or am I missing something. please suggest. Thanks..!!

like image 923
Ankur1994a Avatar asked Jun 08 '16 07:06

Ankur1994a


People also ask

What is Google's People API?

The People API lets you: Read and manage the authenticated user's Contacts. Read and copy the authenticated user's "Other contacts" Read profile information for authenticated users and their contacts. Read domain profiles and contacts.

Does Google contacts have API?

The Contacts API was turned down on January 19, 2022. Use this guide to learn about changes to fields, endpoints, and authorization scopes as you migrate to the People API.

Is Google People API free?

All use of Legacy People API is free of charge. Was this helpful?

What is the point of contact API?

The Contacts API defines a high-level interface to provide access to the user's unified contact information, such as names, addresses and other contact information. The API itself is agnostic of any underlying address book sources and data formats.


2 Answers

People API is more up-to-date. Reading through Google's blog announcement, People API simplifies what needed to be separate calls to Google+ API and Contacts API. Now you only need to use one.

"The new People API uses the newest protocols and technologies and will eventually replace the Contacts API which uses the GData protocol"

When getting the user's list of connections, be sure to specify the correct scopes when using it.

https://www.googleapis.com/auth/contacts - Requests that your app be given read and write access to the contacts in the authenticated user’s Google Contacts. https://www.googleapis.com/auth/contacts.readonly - Requests that your app be given read access to the contacts in the authenticated user’s Google Contacts.

Check this link for similarities and differences between People API and Contacts API.

like image 71
ReyAnthonyRenacia Avatar answered Sep 28 '22 03:09

ReyAnthonyRenacia


I'm not sure if there is any issues with the java code, but if you look at the request that is sent out it should be like this:

URL:https://content-people.googleapis.com/v1/people/me/connections?pageSize=300&requestMask.includeField=person.names%2Cperson.email_addresses&sortOrder=FIRST_NAME_ASCENDING&key=

I was able to get all the contacts with the correct email and name. If you google "manage google contacts" you will see a list of contacts. From there take that number, and just print out the connection count which should match. You just need to make sure the pageSize is big enough or you have to handle paging to get all the contacts.

Also i realized that the requestMask.includeField is really sensitive to what parameters and spaces you put. "person.name,person.email_addresses" worked and "person.name, person.email_addresses" did not.

With the older contact api, you can query the q parameter which I don't think the people api provides this ability. I think the ability to filter your search by key words is important to reduce the request size.

like image 41
darewreck Avatar answered Sep 28 '22 03:09

darewreck