1
我使用google-api-python-client中的內置撤銷方法從django應用創建了一個註銷功能,但它似乎不起作用。這是我的代碼。從google-api-python-client撤銷功能
def google_logout(request, user_id = None):
storage = Storage(CredentialsModel, 'id', user_id, 'credential')
credential = storage.get()
if credential is not None:
cr_json = credential.to_json()
credential = credential.new_from_json(cr_json)
http = httplib2.Http()
http = credential.authorize(http)
try:
# Don't know yet why this is always raising an exception.
credential.revoke(http)
storage.delete()
except TokenRevokeError:
return HttpResponseBadRequest('Invalid Token.')
else:
return redirect('authentication:google_login')
這是工作時,我使用django 1.4.5,但後來我需要升級到1.5.1,現在它不工作。這是一個Django問題嗎?我打賭不是。請幫忙。
P.S.我知道我可以通過手動將access_token傳遞給此url https://accounts.google.com/o/oauth2/revoke?token= {token}來撤銷令牌,但我想使用api中提供的方法。
如果您刪除try:除'TokenRevokeError'外,應該會得到更詳細的錯誤消息。你可以嘗試一下,看看它是否有助於診斷錯誤? –
我試過了,它似乎沒有保存在我的憑證對象中的刷新令牌。我想知道爲什麼它是這樣寫的,雖然它寫在** client.py **'self.params = {'access_type':'offline','response_type':'code',}' –
我有同樣的問題,@PhilamerSune,'access_type'設置爲'offline'(通過API客戶端中的相同流構造函數,就像你使用的那樣),但我顯然沒有在我的憑證對象中得到刷新令牌。不知道如何解決這個問題.... – npdoty