我正在將oAuth 1中的Python應用程序遷移到oAuth 2,該應用程序讀取用戶的Google日曆提要 。使用Python gdata和oAuth 2驗證日曆2
通過OAuth 1: 我的應用程序會打開一個瀏覽器是用戶可以用他的GMail 帳戶進行身份驗證和授權訪問,和我的應用程序將獲得user_token, user_secret該用戶,然後驗證日曆飼料:
client = gdata.calendar.client.CalendarClient(source='test') client.auth_token = gdata.gauth.OAuthHmacToken(app_key, app_secret,user_token,user_secret,gdata.gauth.ACCESS_TOKEN)
由此看來,隱匿對將長期存在。
- 通過OAuth 2: 我登記我的應用程序在谷歌API控制檯並獲得的OAuth 2 CLIENT_ID和client_secret,並修改了應用程序請求 用戶的access_token,從https://accounts.google.com/o/oauth2/token refresh_token對於的GData lib下,我申請這裏指定的gauth.py補丁: http://codereview.appspot.com/4440067/
這是的access_token短暫的。
我玩了一下這裏的代碼http://codereview.appspot.com/4440067/ 並且工作正常。
我的問題:
-I我獲得的access_token,通過捲曲呼叫refresh_token從我 應用程序,我可以成功地同時檢索。然而,當我把它應用到 此代碼:
token =
gdata.gauth.OAuth2Token(client_id=client_id,client_secret=client_secret',
scope='https://www.google.com/calendar/
feeds',user_agent='calendar-cmdline-sample/1.0')
uri = token.generate_authorize_url()
token.get_access_token(access_token)
它給我:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Python/2.6/site-packages/gdata/gauth.py", line 1267,
in get_access_token
raise OAuth2AccessTokenError(error_msg)
gdata.gauth.OAuth2AccessTokenError
- 假設我能成功地做到上面,我可以保存訪問/刷新標記在DB。使用python gdata lib,我怎樣才能使用refresh_token來請求另一個access_token(因此在每次他們使用應用程序授權訪問時都不需要詢問用戶)
非常感謝!
中號