【发布时间】:2015-04-08 00:11:13
【问题描述】:
我正在尝试像这样访问 Spotify API 令牌:
$.ajax({
url: "https://accounts.spotify.com/api/token",
type: 'POST',
contentType: "application/json; charset=\"utf-8\"",
crossDomain: true,
data: {
grant_type: "authorization_code",
code: code,
redirect_uri: "http://www.bancadigital.com.br/spotifyteste/callback.html"
},
processData: false,
dataType: "json",
headers: {
Authorization: "Basic " + utf8_to_b64(key)
},
success: function( response ) {
alert(response.access_token);
},
});
但服务返回以下错误:
XMLHttpRequest 无法加载 https://accounts.spotify.com/api/token。请求的资源上不存在“Access-Control-Allow-Origin”标头。 Origin 'http://www.bancadigital.com.br' 因此不允许访问。
有人知道我如何访问该服务吗?
【问题讨论】:
-
如果他们不允许你 - 你不能使用客户端 JS 来做到这一点。
-
我自己没有使用过 Spotify API,但这个例子可能会有所帮助。 github.com/spotify/web-api-auth-examples/blob/master/…
标签: javascript jquery rest spotify