Google Blogger API:AccessTokenRefreshError:invalid_grand讯息
问题描述:
我使用google-python-client-api作为Blogger API(服务帐户 - OAuth)。Google Blogger API:AccessTokenRefreshError:invalid_grand讯息
这是我的代码(这是考虑我的任务API example)
import httplib2
import pprint
import sys
from apiclient.discovery import build
from oauth2client.client import SignedJwtAssertionCredentials
f = file("privatekey.p12", "rb")
key = f.read()
f.close()
credentials = SignedJwtAssertionCredentials(
"[email protected]",
key,
scope = "https://www.googleapis.com/auth/blogger")
http = httplib2.Http()
http = credentials.authorize(http)
service = build("blogger", "v3", http=http)
当我运行这段代码
,其显示
Message File Name Line Position
Traceback
<module> D:\Code\myScripts\py\gData.py 20
build build\bdist.win32\egg\apiclient\discovery.py 191
new_request build\bdist.win32\egg\oauth2client\client.py 402
_refresh build\bdist.win32\egg\oauth2client\client.py 569
_do_refresh_request build\bdist.win32\egg\oauth2client\client.py 625
AccessTokenRefreshError: invalid_grant
有什么问题,我应该如何解决呢? ?
我甚至尝试tasks.py
示例代码..及其甚至出现同样的错误
我非常确信服务帐户的电子邮件地址是正确
答
我遇到了类似的问题,查询BigQuery。从interwebs上很少有文档可以看出,分辨率较差的时钟会导致时序错误,导致SignedJWTCredentials无效。一种建议的解决方案是确保您的时钟计时器与ntp同步。由于我正在部署到Heroku,因此我的解决方案是优雅地失败,然后重试。请参阅https://code.google.com/p/google-api-php-client/wiki/OAuth2#Solving_invalid_grant_errors