【发布时间】:2020-09-30 01:09:30
【问题描述】:
我正在尝试使用 fetch 请求从 spotify api 获取授权代码,但我不断收到 415 错误代码。当我最初使用 $.ajax 而不是 fetch 时,我没有任何错误。
let client_id = '8f10fa8af1aa40c6b52073811460bf33'
let client_secret = '27a7c01912444b409a7f9a6d1f700868'
let ah = btoa(client_id + ":" + client_secret)
const getAuthToken = (searchedTerm) => {
fetch( `https://accounts.spotify.com/api/token`,
{
headers: {
'Content-Type': 'application/x-www-form-url-encoded',
'Authorization': `Basic ${ah}`
},
body: {
grant_type: 'client_credentials'
},
json: true,
method : "POST"
}
)
.then(function(response) {
authToken = response.access_token;
spotifySearch(response.access_token, searchedTerm);
})
}
【问题讨论】:
-
您对该内容类型的信心如何?您是否尝试将其删除或设置为
application/json? -
是的,我已经尝试将其设置为 application/json,但我仍然得到相同的错误,当我删除它时,我仍然得到相同的错误。
标签: javascript