【发布时间】:2021-05-15 03:23:53
【问题描述】:
我在使用 API 方面完全是初学者,但我正在尝试使用令牌端点将我的秘密交换为 JWT。 (故意删除了client_credentials)
fetch('', {
method: 'POST',
body: 'grant_type=client_credentials&client_id=' + key + '&client_secret=' + secret,
headers: {
"Content-Type": "Bearer [JWT]",
}
}).then(function (resp) {
// Return the response as JSON
return resp.json();
}).then(function (data) {
// Log the API data
console.log('token', data);
}).catch(function (err) {
// Log any errors
console.log('something went wrong', err);
});
我收到此错误:“token {error: "invalid_request", error_description: "grant_type missing"}"
【问题讨论】:
-
试试
body: JSON.stringify({grant_type: client_credentials, client_id: key}) -
出现同样的错误
-
是的,我没有注意到标题错误
标签: javascript api fetch