I want to retrieve my contacts names, email address and phone numbers using the Google People API and I'm using their Try it! tool to test the API.
The names are being retrieved but not the emails addresses and phone numbers. I think I'm doing everything correctly. I'm properly authenticated with the proper scopes and selected fields.
Am I doing something wrong? Or maybe this is an issue on Google's side?
You have to use people.connections.list to fetch the list of contacts, then loop over them and use people.get in order to fetch each individual contact. In my case I set pageSize to 50 and then I use people:batchGet (which supports up to 50 resource names at a time) to fetch the details for those 50 contacts.
I have found a solution. According to the Google People API docs omitting this
RequestMask
field will include all fields but that's not happening. In my case setting theRequestMask
field toperson.names,person.emailAddresses,person.phoneNumbers
works.Just to be clear — because it really wasn't to me — if you are constructing the
GET
request yourself the query parameter for the request mask isrequestMask.includeField
. The nested JSON is flattened to a keypath. So the complete connection listGET
request would be something like:https://content-people.googleapis.com/v1/people/me/connections?requestMask.includeField=person.names,person.addresses,person.email_addresses,person.organizations,person.phone_numbers
Once you have credentials object saved somewhere. You can retrieve the phone numbers and other details by using following code. You just have to set the RequestMask
User's phone numbers and other details will be fetched only if the user has added them to their Google profile.
If you are using Try this API tool and with 'resourceName = people/me', then :
After the consent is given by you, it will be able to fetch 'phoneNumbers' and 'addresses' for the logged in user.
If you want to access other user's profile or you are calling the API from any other source then:
the user must give permission to your app/website/program to access the requested information from his/her profile
you must include 'authorization' KEY in GET REQUEST HEADERS with VALUE "Bearer (OAuth accesstoken of the target user)" to get personal details from the target user's profile.
The OAuth accesstoken can be obtained directly from the user consent response or by exchanging refreshtoken for accesstoken.