我正在尝试通过使用谷歌here所描述的刷新令牌来获取新的访问令牌。谷歌说我需要发出一个HTTP请求。我不知道如何做到这一点,所以我在here上查找了如何做到这一点。但是,我一定是错误地完成了post,因为我得到了一个invalid_request错误。
下面是我的相关代码:
h = Http()
post_data = {'POST': '/o/oauth2/token HTTP/1.1',
'HOST:': 'accounts.google.com',
'Content-Type:': 'application/x-www-form-urlencoded',
'client_id':ClientID,
'client_secret':ClientSecret,
'refresh_token':SavedRefreshToken,
'grant_type':'refresh_token'}
resp, content = h.request("https://accounts.google.com/o/oauth2/token",
"POST",
urlencode(post_data))我得到的回应是:
{
"error" : "invalid_request"
}这里我漏掉了什么?
发布于 2013-04-10 09:46:25
它实际上只是在主体中发送'Content-type',而实际上它应该在头部中发送。此外,您的身体中不需要'POST': '/o/oauth2/token HTTP/1.1'和'HOST:': 'accounts.google.com'。试着这样做:
h = Http()
post_data = {'client_id':ClientID,
'client_secret':ClientSecret,
'refresh_token':SavedRefreshToken,
'grant_type':'refresh_token'}
headers = {'Content-type': 'application/x-www-form-urlencoded'}
resp, content = h.request("https://accounts.google.com/o/oauth2/token",
"POST",
urlencode(post_data),
headers=headers)
print content它应该打印类似这样的内容:
{
"access_token" : "ya29.AHBS6ZCtS8mBc_vEC9FFBkW2x3ipa7FLOs-Hi-3UhVkpacOm",
"token_type" : "Bearer",
"expires_in" : 3600
}https://stackoverflow.com/questions/15915264
复制相似问题