【发布时间】:2018-08-10 09:57:00
【问题描述】:
我正在使用 Google People API 访问我的联系人。
我在 Google Developers Console 中激活它并创建了一个项目、一个服务帐户(以 ....iam.gserviceaccount.com 结尾)和一个以 JSON 格式存储的身份验证密钥。
当我访问联系人时,它似乎使用了我的服务帐户地址而不是我的 Google 帐户的联系人,这导致列表为空。
如何告诉 API 使用我的帐户而不是服务帐户?
这是我目前的代码:
from google.oauth2 import service_account
from googleapiclient.discovery import build
# pip install google-auth google-auth-httplib2 google-api-python-client
SCOPES = ['https://www.googleapis.com/auth/contacts.readonly']
KEY = '~/private.json'
credentials = service_account.Credentials.from_service_account_file(
KEY, scopes=SCOPES)
service = build(
serviceName='people', version='v1', credentials=credentials)
connections = service.people().connections().list(
resourceName='people/me', personFields='names').execute()
print(connections)
# result: {}
【问题讨论】:
标签: python oauth-2.0 google-api google-api-python-client google-people-api