2014-02-27 59 views
0

我想刷新我使用谷歌API按照指示过期的令牌上https://developers.google.com/accounts/docs/OAuth2WebServer#refresh刷新令牌使用谷歌API返回的INVALID_REQUEST

因此,这里是我的代码(蟒蛇)

refresh_token = requests.post(
    'https://accounts.google.com/o/oauth2/token', 
    headers={ 
     'Content-Type': 'application/x-www-form-urlencoded', 
    }, 
    data=json.dumps({ 
     'client_id': APP_ID, 
     'client_secret': APP_SECRET, 
     'refresh_token': refresh_token, 
     'grant_type': 'refresh_token', 
    }) 
) 

不过,我得到的回应:

Status code: 400 
{ 
    "error" : "invalid_request" 
} 

我在做什么错?

回答

1

你正在告诉谷歌服务器,当你的请求实际上是json编码时,你的请求是形式编码的。请求会自动形式编码您的数据,如果你给它一个字典,所以试试这个:

refresh_token = requests.post(
    'https://accounts.google.com/o/oauth2/token', 
    data={ 
     'client_id': APP_ID, 
     'client_secret': APP_SECRET, 
     'refresh_token': refresh_token, 
     'grant_type': 'refresh_token', 
    } 
) 
+0

Thanks!没有意识到这是一个标题问题 – silviomoreto

相关问题