people.connections.list没有使用Python客户端库返回联系人

use*_*003 12 python google-people

我正在尝试使用Python客户端库以编程方式访问我自己的个人Google帐户中的联系人列表

这是一个将在没有用户输入的情况下在服务器上运行的脚本,因此我将其设置为使用我设置的服务帐户中的凭据.我的Google API控制台设置如下所示.

在此输入图像描述

我正在使用以下基本脚本,从API文档中提供的示例中提取 -

import json
from httplib2 import Http

from oauth2client.service_account import ServiceAccountCredentials
from apiclient.discovery import build

# Only need read-only access
scopes = ['https://www.googleapis.com/auth/contacts.readonly']

# JSON file downloaded from Google API Console when creating the service account
credentials = ServiceAccountCredentials.from_json_keyfile_name(
    'keep-in-touch-5d3ebc885d4c.json', scopes)

# Build the API Service
service = build('people', 'v1', credentials=credentials)

# Query for the results
results = service.people().connections().list(resourceName='people/me').execute()

# The result set is a dictionary and should contain the key 'connections'
connections = results.get('connections', [])

print connections  #=> [] - empty!
Run Code Online (Sandbox Code Playgroud)

当我点击API时,它会返回一个没有任何"连接"键的结果集.具体来说它返回 -

>>> results
{u'nextSyncToken': u'CNP66PXjKhIBMRj-EioECAAQAQ'}
Run Code Online (Sandbox Code Playgroud)

是否有与我的设置或代码有关的内容不正确?有没有办法看到响应HTTP状态代码或获得有关它正在尝试做什么的任何进一步的细节?

谢谢!

旁注:当我尝试使用"试试吧!"时 API文档中的功能,它正确返回我的联系人.虽然我怀疑它使用客户端库而是依赖于OAuth的用户授权

B. *_*hon 6

personFields面具是必需的.指定一个或多个有效路径.有效路径记录在https://developers.google.com/people/api/rest/v1/people.connections/list/中.

此外,使用字段掩码指定部分响应中包含哪些字段.

代替:

results = service.people().connections().list(resourceName='people/me').execute() 
Run Code Online (Sandbox Code Playgroud)

...尝试:

results = service.people().connections().list(resourceName='people/me',personFields='names,emailAddresses',fields='connections,totalItems,nextSyncToken').execute() 
Run Code Online (Sandbox Code Playgroud)