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 name
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
#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