要访问 TokenInfo,我使用 Python 的 Google API 客户端库(oauth2client 应用程序引擎)。我收到了一个 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"
}
更新-1
我研究了 oauth2client\client.py : decorator.http() 不仅对请求进行授权,而且如果 access_token 已过期,还会刷新它。
我非常欢迎关于如何解决这个问题的想法?谢谢你的帮助。
UPDATE-2 并已解决
TokeInfo API 不需要任何授权。请求本身必须包含 access_token。授权标头被忽略。