Spoltify 令牌返回错误 415 angular

Spoltify token returning error 415 angular

我想从 spotify 获取访问令牌 api 这是我的要求:

this.http.post("https://accounts.spotify.com/api/token", {
      headers: { 
        'Authorization' : "Basic " + CryptoJS.enc.Base64.stringify(CryptoJS.enc.Utf8.parse("ID:Secret")),
        'Content-Type':'application/x-www-form-urlencoded'
      },
      params: {
        grant_type : "authorization_code",
        code : code,
        redirect_uri : "REDIRECT URL"
      }
    }).subscribe(data => {
        console.log(data)
    })

我在控制台中收到此错误: “https://accounts.spotify.com/api/token 的 HTTP 失败响应:415 OK”

我认为您必须使用之前的参数创建一个 HttpParams 对象,例如:

let httpParams = new HttpParams()
    .append("grant_type", "authorization_code")
    .append("code", "code")
    .append("redirect_uri", "redirect_uri");

this.http.post("https://accounts.spotify.com/api/token", httpParams.toString(), {
      headers: { 
        'Authorization' : "Basic " + CryptoJS.enc.Base64.stringify(CryptoJS.enc.Utf8.parse("ID:Secret")),
        'Content-Type':'application/x-www-form-urlencoded'
      }
    }).subscribe(data => {
        console.log(data)
    })