[英]gmail api gives failedPrecondition error
我無法讓gmail api工作。 我正在使用JWT進行服務器到服務器身份驗證。
google-api-python-client==1.4.0
httplib2==0.9
oauth2client==1.4.7
pycrypto==2.6.1
我的代碼看起來像這樣。
with open(CLIENT_SECRET_FILE) as f:
data = json.loads(f.read())
private_key = data['private_key']
client_email = data['client_email']
credentials = SignedJwtAssertionCredentials(client_email, private_key, scope=OAUTH_SCOPE)
http = credentials.authorize(http)
gmail_service = build('gmail', 'v1', http=http)
try:
threads = gmail_service.users().messages().list(userId='me').execute()
except Exception as e:
print e
print e.content
回應是
<HttpError 400 when requesting https://www.googleapis.com/gmail/v1/users/me/messages?alt=json returned "Bad Request">
{
"error": {
"errors": [
{
"domain": "global",
"reason": "failedPrecondition",
"message": "Bad Request"
}
],
"code": 400,
"message": "Bad Request"
}
}
謝謝。
嘗試:
credentials = SignedJwtAssertionCredentials(client_email,
private_key,
scope=OAUTH_SCOPE,
sub='user@yourdomain.com')
sub =告訴服務帳戶您要模擬哪個帳戶。 沒有它,您將作為服務帳戶用戶進行身份驗證,正如Eric指出的那樣,該用戶沒有Gmail郵箱。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.