Why can't I get email addresses and phone numbers using the Google People API?

I want to get contact names, email address and phone numbers using the Google People API , and I use them Try it! API testing tool.

Names are retrieved, but not email addresses and phone numbers . I think I'm doing it right. I am authenticated correctly with the corresponding fields and selected fields. enter image description here enter image description here

Am I doing something wrong? Or maybe this is a problem on the side of Google?

+6
source share
5 answers

I have found a solution. According to the Google People API docs, omitting this RequestMask field will display all fields, but this does not happen. In my case, setting RequestMask to person.names,person.emailAddresses,person.phoneNumbers works.

+15
source

You must use people.connections.list to retrieve the contact list, then iterate over them and use people.get to get 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 get data for these 50 contacts.

+2
source

Just to be clear - because it really wasn't for me - if you yourself create a GET request, the request parameter for the request mask is requestMask.includeField . Nested JSON is flattened to the key path. Thus, a request for a complete GET netlist would look something like this:

https://content-people.googleapis.com/v1/people/me/connections?requestMask.includeField=person.names,person.addresses,person.email_addresses,person.organizations,person.phone_numbers

+2
source

Once you have the credentials, the object is saved somewhere. You can get phone numbers and other data using the following code. You just need to install RequestMask

 #get the credentials cred_obj = OAuth2Credentials.new_from_json(credentials) http = httplib2.Http() #create service people_service = build(serviceName='people', version='v1', http=cred_obj.authorize(http)) results = people_service.people().connections().list(resourceName='people/me', requestMask_includeField='person.names,person.emailAddresses,person.phoneNumbers', pageSize=160) res = results.execute() connections = res.get('connections', []) for person in connections: names = person.get('names', []) phone_numbers = person.get('phoneNumbers', []) if len(names) > 0: name = names[0].get('displayName') if len(phone_numbers)>0: phone_no = phone_numbers[0].get('value') print name, phone_no 
+1
source

Custom phone numbers and other data will only be obtained if the user adds them to his Google profile.

If you use try this API and with 'resourceName = people / me', then:

  • you must log in to your Google account and
  • give your consent to allow the google API explorer tool to access the profile registered in the user's profile (in this case yours). See an example here.

After you give your consent, he will be able to get "phoneNumbers" and "addresses" for the registered user.

If you want to access another user profile or you are calling the API from any other source, then:

  • the user must grant permission to your application / website / program to access the requested information from his profile

  • you must enable KEY "authorization" in GET REQUEST HEADERS with VALUE "Bearer (OAuth accesstoken from target user)" in order to get personal data from the target user profile.

OAuth accesstoken can be obtained directly from a user consent response or by exchanging a refreshtoken for accesstoken.

+1
source

All Articles