【发布时间】:2017-02-14 16:30:52
【问题描述】:
我这几天一直在研究 Spotify api 和示例源代码,但我仍然不知道如何获取访问令牌来访问用户的播放列表数据。我已经到了打开登录窗口,用户登录,然后我收到一个授权码的地步。此时,我尝试执行以下操作:
window.open("https://accounts.spotify.com/api/token?
grant_type=authorization_code&code="+code+"&redirect_uri=myurl&client_id=3137b15
2f1424defa2c6020ae5c6d444&client_secret=mysecret");
和
$.ajax(
{
url: "https://accounts.spotify.com/api/token?grant_type=authorization_code&code="+code+"&redirect_uri=myurl&client_secret=mysecret&client_id=myid",
success: function(result){
alert("foo");
}
}
);
但无论哪种方式,我都会得到如下结果:
{"error":"server_error","error_description":"Unexpected status: 405"}
而不是令牌。我敢肯定这很简单,但我在 JS 方面很糟糕。请帮忙!谢谢!
(编辑)我忘了说:
api认证指南链接:https://developer.spotify.com/web-api/authorization-guide/
我被困在第 4 步。我发现有另一种方法可以发送“标头参数”或 cURL 请求,它可能会起作用。但是,鉴于我不知道如何做这些事情,我一直坚持将 client_id 和 client_secret 作为正文请求参数发送,就像我之前为用户登录/代码所做的那样。
PS:我只使用我为自己编写的这个应用程序。有没有一种方法可以在不经过此过程的情况下硬编码令牌?
【问题讨论】:
标签: javascript html ajax xmlhttprequest spotify