【问题标题】:Error 400 on spotify web api. Need hlp plsSpotify Web api 上的错误 400。需要帮助请
【发布时间】:2021-03-10 14:39:09
【问题描述】:

对不起这个标题,但我真的需要 hlp。我不知道为什么这不起作用,我搜索了很多。

所以我正在使用 Spotify Api,我想访问 Access_Token。文档说你必须这样做:Spotify Documentation

我要求这样:

  fetch ('https://accounts.spotify.com/api/token', {
method: 'post',
body: {
  code: code,
  redirect_uri: redirectUri,
  grant_type: 'authorization_code'
},
headers: {
  'Content-Type': 'application/x-www-form-urlencoded',
  Authorization: 'Basic ' + btoa(clientId+':'+clientSecret)
},
json: true
 })

但这就是回答这个问题: Error

我检查并发现错误 400 表示“错误请求”。

你有想法吗?感谢您的帮助!

【问题讨论】:

    标签: javascript api spotify client-side


    【解决方案1】:

    查看您的错误,没有收到任何正文。您必须将其作为 json 字符串发送:

    let body = {
      code: code,
      redirect_uri: redirectUri,
      grant_type: 'authorization_code'
    }
    fetch ('https://accounts.spotify.com/api/token', {
    method: 'post',
    body: JSON.stringify(body),
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
      Authorization: 'Basic ' + btoa(clientId+':'+clientSecret)
    },
    json: true
     })
    

    【讨论】:

    • 仍然无法正常工作:(这是错误:Failed to load resource: the server responded with a status of 400 ()
    • 400 表示您发送的数据不正确。您的 clientId 和 secret 是否正确?你可以用 Postman 之类的手动尝试吗?
    猜你喜欢
    • 1970-01-01
    • 2021-09-10
    • 2018-06-07
    • 1970-01-01
    • 2020-11-13
    • 2017-11-22
    • 2017-10-09
    • 2011-09-02
    • 1970-01-01
    相关资源
    最近更新 更多