【发布时间】:2017-04-05 09:30:13
【问题描述】:
我有两个 curl-strings,它们首先执行 OAuth2-Token-Request,然后从 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/token
Test.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' } 而 CURL 给了我正确的 access_token。
有人可以帮忙吗?谢谢!!
【问题讨论】:
-
您的代码中似乎有错字:mehtod => method
-
哈哈。这样的菜鸟错误......现在它说“{代码:401,消息:'未授权。' }"
标签: node.js curl oauth-2.0 access-token