仅从我填充的联系人个人资料中检索字段

时间:2019-06-05 19:47:52

标签: python-3.x google-people

我正在尝试使用Google People API来获取有关我的联系人的完整信息,前提是他们已将这些信息设置为公开。我在为自己未填写的任何字段获取值时遇到问题。例如,我知道我的老板填写了诸如“教育”,“职业”等字段。但是当我尝试使用以下命令查看这些字段时:```

people.get(resourceName=boss, personFields = "names, phoneNumbers, education, occupation")

我只会找回我填写的字段(姓名和电话号码)。

最初,我尝试从connections.list获取所有这些信息,但现在尝试使用connections.list获得的资源名称进行显式获取。 我还对自己({people / me“)尝试过people.get(),但由于以下错误而崩溃了:

raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 403 when requesting https://people.googleapis.com/v1/people/me?personFields=locales%2Cnames%2Cnicknames%2Cgenders%2CageRanges%2Cbirthdays%2Cevents%2Caddresses%2CemailAddresses%2CphoneNumbers%2CimClients%2Ctaglines%2Cbiographies%2Corganizations%2Coccupations%2Cinterests%2Cskills%2Crelations%2CrelationshipInterests%2Cmemberships&alt=json returned "The caller does not have permission to request "people/me". Request requires one of the following scopes: [profile].">

该项目使用多个API,这是我授权时要求的范围:

SCOPES = ['https://www.googleapis.com/auth/gmail.readonly','https://www.googleapis.com/auth/contacts','https://www.googleapis.com/auth/calendar.readonly']

下面是代码部分,我从我的联系人那里获取资源名称(老板的名字是字典conns中的键)。

results = service.people().connections().list(resourceName='people/me',
        pageSize=500,sortOrder='FIRST_NAME_ASCENDING',
        personFields=','.join(queryFields)).execute()
    connections = results.get('connections', [])
    tempPeople = []
    for person in connections:
        names = person['names']
        if names:
            name = names[0]['displayName']
            if name in conns.keys():
                tempPeople.append(person)
    people = []
    boss = tempPeople[1]['resourceName']
    res = service.people().get(resourceName=boss,personFields=",".join(queryFields)).execute()
    print(res.keys())

请注意,查询字段是一个列表,其中包含Google People API中概述的几乎所有可能的人员字段。 当我打印res.keys()时,我目前仅获得resourceName,etag,名称,电话号码和成员资格。我希望能看到一些教育,职业和电子邮件地址。

任何方向将不胜感激。我现在正在拔头发。

0 个答案:

没有答案