我试图以编程方式访问使用Python客户端库我自己的个人帐户谷歌联系人列表中的联系人people.connections.list没有返回使用Python客户端库
这是将上运行脚本服务器没有用户输入,所以我设置了使用来自我设置的服务帐户的凭证。我的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!
当我打的API返回,没有任何“关系”的结果集键。具体而言,它返回 -
>>> results
{u'nextSyncToken': u'CNP66PXjKhIBMRj-EioECAAQAQ'}
是否有某些与我的设置或代码有关的错误?有没有办法查看响应HTTP状态代码或获取关于它想要做什么的更多细节?
谢谢!
旁注:当我尝试使用the "Try it!" feature in the API docs,它正确返回我的联系人。虽然我怀疑是否使用客户端库,而是依赖于通过OAuth进行的用户授权
嘿,我有完全一样的问题。你能解决它吗?谢谢。 – katericata
@katericata - 我没有,对不起:( – user2490003