【发布时间】:2017-07-02 12:25:06
【问题描述】:
我正在关注本教程Using OAuth 2.0 for Server to Server Applications。我正在尝试使用服务帐户连接到 Gmail API。
我最终得到的代码如下所示:
from oauth2client.service_account import ServiceAccountCredentials
from httplib2 import Http
from apiclient.discovery import build
import json
scopes = ['https://www.googleapis.com/auth/gmail.readonly']
credentials = ServiceAccountCredentials.from_json_keyfile_name('******.json', scopes)
http_auth = credentials.authorize(Http())
service = build('gmail', 'v1', http=http_auth)
request = service.users().messages().list(userId='me')
response = request.execute()
print json.dumps(response, sort_keys=True, indent=2)
但是,当我运行此代码时,我收到以下错误:
googleapiclient.errors.HttpError:https://www.googleapis.com/gmail/v1/users/me/messages?alt=json 返回“错误请求”>
有人可以帮助我了解此错误的来源吗?
【问题讨论】:
标签: python google-api google-oauth gmail-api service-accounts