【问题标题】:spotify api axios react post request 403 errorspotify api axios react post request 403错误
【发布时间】:2018-12-28 18:28:52
【问题描述】:
makePlaylist = event => {
        event.preventDefault()
        let token = localStorage.getItem('token')
        let playlist = {name: this.state.text, public:false}
        axios.post(
            `https://api.spotify.com/v1/users/${this.state.user_id}/playlists`, playlist,
          {headers: {
            "Authorization": 'Bearer ' + token
          }
        }
        )
        .then(response => {
            console.log(response)
        })
        .catch(error => {
            console.log(error)
        })
    }

我收到以下错误

https://api.spotify.com/v1/users/my_user_id_here/playlists 403 error

我在网上查阅了文档

https://developer.spotify.com/documentation/web-api/reference/playlists/create-playlist/

据我所知,我似乎在进行设置。有人知道我对请求做错了什么吗?我知道访问令牌是有效的。

【问题讨论】:

  • 您可以尝试将“Content-Type”标头指定为“application/json”
  • 哇试过了。在授权下方添加行“Content-Type”:“application/json”并得到相同的403错误。
  • 您是否在授权请求中添加了 playlist-modify-private 范围?

标签: reactjs axios spotify


【解决方案1】:

“在没有用户授权的情况下尝试创建播放列表会返回错误 403 Forbidden。”确保您在 Dashboard 中创建的 Spotify 应用对您尝试为其创建播放列表的用户具有适当的范围权限。

这是创建私人播放列表的范围:https://developer.spotify.com/documentation/general/guides/scopes/#playlist-modify-private

以下是通过传入范围设置授权的教程: https://developer.spotify.com/documentation/general/guides/authorization-guide/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-07-22
    • 2019-10-19
    • 2021-11-25
    • 2019-07-12
    • 2020-02-04
    • 1970-01-01
    • 2021-02-06
    • 1970-01-01
    相关资源
    最近更新 更多