豆瓣oauth调用出错?
用nodejs的superagent客户端来调用豆瓣oauth,要获取的access_token的时候老出现
javascript
required_parameter_is_missing: client_id
的问题。有人遇到这种问题吗?豆瓣上面有好多人问,但是都解决不了我的问题:
我的代码:
exports.user_info = function (code) {
return request.post(config.douban.authorize_token_url)
.send("client_id", config.douban.app_id)
.send("client_secret", config.douban.app_secret)
.send("redirect_uri", config.back.code_back_url)
.send("grant_type", "authorization_code")
.send("code", code)
.set("ContentType", "application/x-www-form-urlencoded")
.end(function (res) {
console.log(res.text);
return request.get(config.douban.user_info_url + res.body.douban_user_id)
.set("Authorization", "Bearer " + res.body.access_token)
.end(function (response) {
console.log(response.text);
return response;
});
});
};
错误类似豆瓣上的问题, http://www.douban.com/group/topic/40590418/ 。再把app_id贴出来大家帮着看看:05a8eec5691e6dcf10facc503b5b496d。由于code可以正确得到所有app_id肯定没有问题。
按照楼下的建议,我用python试了一下:
>>> url = token_url + urllib.urlencode(params)
>>> url
'https://www.douban.com/service/auth2/tokencode=dbf492bfa678692e&client_secret=ec0faf30f04562a6&redirect_uri=https%3A%2F%2Fwww.douban.com%2Fservice%2Fauth2%2Ftoken&client_id=05a8eec5691e6dcf10facc503b5b496d&grant_type=authorization_code'
>>> url = token_url + "?"+urllib.urlencode(params)
>>> url
'https://www.douban.com/service/auth2/token?code=dbf492bfa678692e&client_secret=XXXXXXXXX&redirect_uri=https%3A%2F%2Fwww.douban.com%2Fservice%2Fauth2%2Ftoken&client_id=05a8eec5691e6dcf10facc503b5b496d&grant_type=authorization_code'
>>> from requests import *
>>> post(url)
<Response [400]>
>>> post(url).text
u'{"msg":"required_parameter_is_missing: client_id","code":113,"request":"POST \\/auth2\\/token"}'
>>>
豆瓣上面好像说也可以把参数放在url后面所以我就试了一下,问题依旧啊。
红眼睛小萝莉
10 years, 9 months ago