我試圖以編程方式訪問使用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