我正在使用Lyft API,并试图弄清楚如何使用带有节点脚本的 axios 获取访问令牌。
我可以通过填写如下表格使用 Postman 手动获取访问令牌:
当我填写表格时,我可以成功地从 Lyft 获得一个新的令牌。
我正在尝试通过执行以下操作将其转换为使用 axios 的 POST 请求:
var axios = require('axios');
var data = {
"grant_type": "client_credentials",
"scope": "public",
"client_id": "XXXXXXXXX",
"client_secret": "XXXXXXXX"
};
var url = "https://api.lyft.com/oauth/token";
return axios.post(url, data)
.then(function(response){
console.log(response.data)
})
.catch(function (error) {
console.log(error);
});
当我运行脚本时,我收到此错误:
{ error_description: 'Unauthorized', error: 'invalid_client' }
我的 axios 请求中缺少什么?任何帮助,将不胜感激!