2012-08-09 53 views
1

突然,在我的應用程序被授予用戶訪問權限並且授權代碼傳遞到我的重定向url後,Oauth進程中出現錯誤。我已經使用相同的代碼幾個星期了,它一直工作正常。我很確定我沒有做任何改變。交換Oauth代碼時出錯

今天Google Drive API有問題嗎?

這裏發生在Python代碼這裏的誤差:

credentials = flow.step2_exchange(authorization_code) 

錯誤消息:

FlowExchangeError: Invalid response 400. 

來自谷歌例如複製的整個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遊樂場,我收到以下錯誤響應:

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" 
} 

任何想法,爲什麼這將開始發生時,代碼工作幾周,因爲它是現在?

謝謝, 克里斯

回答

0

我終於能得到代碼再次工作。我將GAE應用程序版本恢復到了以前的版本。 Oauth exchange_code再次工作。然後我把它帶回GAE的最新版本,不管代碼如何變化,它都能繼續工作。

因此,當我最近在GAE中創建新版本時沒有更改代碼,oauth進程確實停止工作。爲什麼它的價值.....

1

HTTP響應代碼400意味着你的要求是某種無效,應該有一個更具體的錯誤信息,告訴你什麼是錯的。

也許Python庫是隱藏完整的消息,我建議你嘗試使用OAuth 2.0遊樂場相同的請求,並比較它與你:

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

+0

感謝克勞迪奧,我編輯了問題,以顯示出答覆出OAuth 2.0 Playground – user1501783 2012-08-10 03:25:48

+0

你也可以添加請求嗎?隨意刪除敏感細節 – 2012-08-10 03:34:52

+0

我不知道如何顯示實際請求,除了上面首先列出的失敗行之外:credentials = flow.step2_exchange(authorization_code)。我假設'流'是在其中一個導入中定義的:從oauth2client.client導入FlowExchangeError。來自oauth2client.client的 導入AccessTokenRefreshError。來自oauth2client.client的 import Credentials ...你能告訴我如何看到發送的實際請求嗎? – user1501783 2012-08-10 03:43:13