【发布时间】:2012-02-26 18:11:12
【问题描述】:
在这两种情况下,我都尝试使用 OAuth 1.0 和 2.0 访问 Google 的 API,我需要使用值“OAuth”填充标题中的授权字段,然后是访问令牌。我尝试了以下方法,但 Google 向我抛出了一个错误,提示 Authorization 标头值存在问题。我正在使用 Python-Tornado
additional_headers = {
"Authorization": "OAuth "+GoogleOAuth2Mixin.access_token,
"Accept-Encoding": None
}
h = httputil.HTTPHeaders()
h.parse_line("Authorization: OAuth "+GoogleOAuth2Mixin.access_token)
request = httpclient.HTTPRequest(self._USER_INFO_URL+"?access_token="+GoogleOAuth2Mixin.access_token, method="GET", headers=h)
self.httpclient_instance.fetch(
request,
self.async_callback(callback)
)
我尝试通过传递标头“h”和“additional_headers”来使用这两种方法,但它不起作用。什么是准确的方法?
【问题讨论】:
-
你得到的确切错误是什么?
-
这是我看到的错误:{ "error": { "errors": [ { "domain": "com.google.auth", "reason": "invalidAuthentication", "message" : "invalid token", "locationType": "header", "location": "Authorization" } ], "code": 401, "message": "invalid token" } }
-
我在成功验证后看到了这个错误 - googleapis.com/oauth2/v1/tokeninfo
-
我不认为
GoogleOAuth2Mixin.access_token是获取访问令牌的正确方法。我还没有对此进行测试,但您应该能够从get_authenticated_user返回的用户信息中获取它。