Why can't I retrieve emails addresses and phone numbers with Google People API?

后端 未结 5 1931
有刺的猬
有刺的猬 2020-12-29 00:59

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

5条回答
  •  南笙
    南笙 (楼主)
    2020-12-29 01:31

    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

提交回复
热议问题