【发布时间】:2019-08-17 09:28:08
【问题描述】:
我在向 Reddit 发出请求以获取访问令牌时收到 unsupported_grant_type 错误。我正在尝试制作一个在没有用户上下文的情况下发出 API 请求的应用程序。
我试过移动参数和标题,但无济于事。
这是我目前使用的代码(请注意,我的用户名 = '我的客户 ID' 和密码 = '我的密钥'
var request = require("request");
var auth = 'Basic ' + Buffer.from(username + ':' + password).toString('base64');
var options = { method: 'POST',
url: 'https://www.reddit.com/api/v1/access_token',
headers:
{ 'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': auth,
},
body:
JSON.stringify({grant_type: 'client_credentials',
user: username,
password: password})
};
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(response,body);
});
【问题讨论】:
标签: javascript node.js request reddit