【问题标题】:Spotify Web Api Token Request Response 400Spotify Web Api 令牌请求响应 400
【发布时间】:2017-11-22 01:44:01
【问题描述】:

现在我正在尝试通过 Spotify Web Api 中的授权代码流方法将我的授权代码交换为令牌,但作为响应,我总是得到 400 状态。这是我正在使用的代码:

HttpPost httppost = new HttpPost(new URI("https://accounts.spotify.com/api/token/?grant_type=authorization_code&code=" + tempCode + "&redirect_uri=" + RedirectUri));
    httppost.addHeader("Authorization",  "Basic " + Base64.encodeBase64String((ClientId + ":" + ClientSecret).getBytes()));
    httppost.setProtocolVersion(HttpVersion.HTTP_1_1);

谢谢你帮助我!

【问题讨论】:

    标签: java http spotify


    【解决方案1】:

    去掉标记后的斜线

    应该是https://accounts.spotify.com/api/token

    另外,请求参数应该在 POST 正文中,而不是在 URI 中。

    【讨论】:

    • 谢谢,“修复”了这个错误。现在我得到了一个适当的响应体。但它仍然无法正常工作。状态为 400,正文显示:{"error":"server_error","error_description":"Unexpected status: 400"}
    • 那么您正在发布,所以您应该将所有请求参数放在 POST 正文中,而不是放在 URI 中。您的 POST URI 只能是 accounts.spotify.com/api/token。你明白吗?
    • 谢谢!傻我没想到。现在一切正常! :)
    猜你喜欢
    • 2020-01-04
    • 2016-11-02
    • 1970-01-01
    • 1970-01-01
    • 2018-06-07
    • 1970-01-01
    • 2014-10-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多