【问题标题】:Spoltify token returning error 415 angularSpoltify 令牌返回错误 415 角度
【发布时间】:2020-08-05 00:29:56
【问题描述】:

我想从 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"

【问题讨论】:

    标签: javascript angular api ionic-framework spotify


    【解决方案1】:

    我认为您必须先使用参数创建一个 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)
        })
    

    【讨论】:

    • 不工作:(-
    • 尝试将参数作为正文发送this.http.post("url", httpParams.toString(), {headers: {...}})@XetaWays
    • 你有运气吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-22
    • 2019-01-26
    • 2014-10-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多