交换Oauth代码时出错

时间:2012-08-09 23:51:16

标签: google-drive-api

突然之间,在我的应用被授予用户访问权限并且授权代码被传递到我的重定向网址之后,我在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"
}

有什么想法为什么会在代码工作几周之后开始发生这种情况?

谢谢, 克里斯

2 个答案:

答案 0 :(得分:1)

HTTP响应代码400意味着您的请求在某种程度上无效,并且应该有更具描述性的错误消息,告诉您哪里出错了。

也许Python库隐藏了完整的消息,我建议您尝试使用OAuth 2.0 Playground进行相同的请求并与之进行比较:

https://code.google.com/oauthplayground/

答案 1 :(得分:0)

我终于能够让代码再次运行了。我将GAE应用版本恢复为我之前的版本。 Oauth exchange_code再次运作。然后我把它带回到GAE上的当前版本,没有对代码进行任何更改,它继续工作。

因此,当我最近在GAE中创建新版本而没有更改代码时,oauth进程确实停止了工作。为了它的价值......