2014-01-16 22 views
0

我使用Python庫requests-oauthlib爲了創建一個應用程序,可以與一些主要提供商(谷歌,Dropbox,Facebook,Twitter)使用OAuth。
示例代碼提供here給我一個例外:
通過Python庫請求使用OAuth與谷歌 - oauthlib拋出異常MissingCodeError

raise MissingCodeError("Missing code parameter in response.") 
oauthlib.oauth2.rfc6749.errors.MissingCodeError: Missing code parameter in response. 

的問題是不是在說我與谷歌API控制檯創建網絡應用客戶端,因爲我寫的另一段代碼做同樣的事情,但使用Python庫google-api-python-client並且工作正常。

有什麼想法?

回答

1

我的錯!

google.fetch_token(token_url, client_secret=client_secret, authorization_response=redirect_response) 

,要求redirect_response是一個完整的URL:

我,因爲使用弄糊塗了。 在使用:

google.fetch_token(token_url, client_secret=client_secret, 
... code=redirect_response) 

,要求redirect_response只有通過谷歌說的代碼。

+0

我實際上遇到同樣的錯誤...你能分享你的解決方案嗎?這是我遵循的例子:http://requests-oauthlib.readthedocs.org/en/latest/examples/github.html –

+0

很久以前,我不記得所有細節。但我想redirect_response就像'http://googlewhatever.../?code = mycode'。如果'redirect_response ='http://googlewhatever.../?code = mycode'',那麼寫在答案中的第一段代碼就可以工作。如果'redirect_response ='mycode'' – nimiq

+0

感謝您的回覆,第二段代碼就可以工作。你最終使用了哪個OAUTH庫? –