1
要訪問TokenInfo我使用Python中的谷歌API客戶端庫(oauth2client應用程序引擎)。 我收到OAuth2用戶訪問令牌和該代碼工作正常:無法使用decorator.http tokeninfo的oauth2請求授權()
@decorator.oauth_aware
def get(self):
....
....
if decorator.has_credentials() :
body = urllib.urlencode({'access_token': decorator.credentials.access_token})
http = httplib2.Http()
resp, content = http.request("https://www.googleapis.com/oauth2/v1/tokeninfo",method="POST", body=body)
但是當我使用的裝飾來創建一個授權HTTP實例:
@decorator.oauth_aware
def get(self):
....
....
if decorator.has_credentials() :
http = decorator.http()
resp, content = http.request("https://www.googleapis.com/oauth2/v1/tokeninfo",method="POST")
我收到:
'status' : '400'
{
"error": "invalid_token",
"error_description": "either access_token or id_token required"
}
UPDATE-1
我研究了oauth2client \ client.py:decorator.http()不僅授權請求,而且刷新access_token(如果已過期)。
我非常歡迎有關如何解決這個問題的想法?謝謝你的幫助。
UPDATE-2,解決
的TokeInfo API不需要任何授權。請求本身必須包含access_token。授權標頭被忽略。