我正在關注本教程Using OAuth 2.0 for Server to Server Applications。我正嘗試使用服務帳戶連接到Gmail API。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 returned "Bad Request">
有人可以幫助我明白的地方這個錯誤來自哪裏?