【发布时间】:2020-09-29 22:34:45
【问题描述】:
我在尝试 POST 请求时收到此错误消息:
{
"error": {
"status": 401,
"message": "No token provided"
}
}
问题是我通过创建 headers 变量并将其分配给 post 请求的 headers 来传递访问令牌,如下所示:
const headers = {
Authorization: `Bearer ${accessToken}`
}
return fetch(`https://api.spotify.com/v1/users/${userId}/playlists`, {
'headers': headers,
method: 'POST',
body: JSON.stringify({'name': name})
这个获取请求是给我上面所说的错误的那个。我该如何解决这个问题?
Headers object picture right before the fetch request
这里是 GitHub 的链接:https://github.com/aoljaca/jamming
此代码在 src/utils/Spotify 文档中
谢谢!
【问题讨论】:
-
文档说格式必须是
Authorization: Basic *<base64 encoded client_id:client_secret>*。查看节标题参数。 developer.spotify.com/documentation/general/guides/… 我相信它使用Basic作为 auth 标头。 -
是的,我正在使用隐式授权流developer.spotify.com/documentation/general/guides/…,但是我很确定它不需要客户端密码
标签: javascript reactjs spotify