我有两个卷曲字符串,它们首先执行OAuth2令牌请求,然后从API加载数据。现在我想把它包含到一个node.js插件中,所以我需要在插件中这样做。
卷曲:
curl -X POST -d 'grant_type=password&client_id=8d3c1664-05ae-47e4-bcdb-477489590aa4&client_secret=4f771f6f-5c10-4104-bbc6-3333f5b11bf9&username=email&password=password' https://api.hello.is/v1/oauth2/tokenTest.js:
var request = require('request');
request({
url: 'https://api.hello.is/v1/oauth2/token',
mehtod: "POST",
auth: {
username: 'email',
password: 'password'
},
form: {
'grant_type': 'password',
'client_id': '8d3c1664-05ae-47e4-bcdb-477489590aa4',
'client_secret': '4f771f6f-5c10-4104-bbc6-3333f5b11bf9'
}
}, function(err, res) {
var json = JSON.parse(res.body);
console.log("Access Token:", json.access_token)
});问题是,我得到的唯一东西是:{ code: 405, message: 'Method not allowed' },而卷曲给了我正确的access_token。
有人能帮忙吗?谢谢!!
发布于 2016-11-21 22:31:38
也许试一试:
var request = require('request');
request({
url: 'https://api.hello.is/v1/oauth2/token',
mehtod: "POST",
form: {
username: 'email',
password: 'password',
grant_type: 'password',
client_id: '8d3c1664-05ae-47e4-bcdb-477489590aa4',
client_secret: '4f771f6f-5c10-4104-bbc6-3333f5b11bf9'
}
}, function(err, res) {
var json = JSON.parse(res.body);
console.log("Access Token:", json.access_token)
});https://stackoverflow.com/questions/40729452
复制相似问题