突然,在我的应用程序被授予用户访问权限并且授权码被传递到我的重定向 URL 之后,我在 Oauth 过程中遇到了一个错误。几周以来,我一直在使用相同的代码,并且运行良好。我很确定我没有做任何改变。
今天 Google Drive API 有问题吗?
错误发生在此处的 Python 代码中:
credentials = flow.step2_exchange(authorization_code)
错误信息:
FlowExchangeError: Invalid response 400.
从 Google 示例复制的整个 exchange_code 方法:
def exchange_code(authorization_code):
"""Exchange an authorization code for OAuth 2.0 credentials.
Args:
authorization_code: Authorization code to exchange for OAuth 2.0
credentials.
Returns:
oauth2client.client.OAuth2Credentials instance.
Raises:
CodeExchangeException: an error occurred.
"""
logging.debug(authorization_code);
flow = flow_from_clientsecrets(CLIENTSECRETS_LOCATION, ' '.join(SCOPES))
flow.redirect_uri = REDIRECT_URI
try:
credentials = flow.step2_exchange(authorization_code)
return credentials
except FlowExchangeError, error:
logging.error('An error occurred: %s', error)
raise CodeExchangeException(None)
使用 Oauth Playground,我得到以下错误响应:
HTTP/1.1 400 Ok
Status: 400
Content-length: 37
X-xss-protection: 1; mode=block
X-content-type-options: nosniff
X-google-cache-control: remote-fetch
-content-encoding: gzip
Server: GSE
Via: HTTP/1.1 GWA
Pragma: no-cache
Cache-control: no-cache, no-store, max-age=0, must-revalidate
Date: Fri, 10 Aug 2012 03:23:54 GMT
X-frame-options: SAMEORIGIN
Content-type: application/json
Expires: Fri, 01 Jan 1990 00:00:00 GMT
{
"error" : "unauthorized_client"
}
任何想法为什么当代码像现在这样工作了数周时会开始发生这种情况?
谢谢,克里斯