【发布时间】:2017-06-16 03:25:56
【问题描述】:
我尝试将曲目添加到协作播放列表,这是我的访问令牌代码
$credentials = 'client_id:client_secret';
$headers = array(
'Accept: */*',
'Content-Type: application/x-www-form-urlencoded',
'User-Agent: runscope/0.1',
'Authorization: Basic '.base64_encode($credentials));
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://accounts.spotify.com/api/token');
curl_setopt($ch, CURLOPT_HTTPHEADER,$headers);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,'grant_type=client_credentials');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$response = json_decode($response, true);
echo $token = $response['access_token'];
curl_close($ch);
在我的页面中,用户未登录,因此我创建了协作播放列表
这是我的add playlist 函数
var addplaylist = function (id,token) {
$.ajax({
dataType: 'text',
type: 'post',
url: 'https://api.spotify.com/v1/users/entelperú/playlists/6sU8XOS7BLicR3COsc0Rhp/tracks?uris=spotify:track:'+ id,
headers: {
Authorization: "Bearer "+token,
},success: function (response) {
alert(response);
}
});
};
但它会返回这个
{ “错误” : { “状态”:403, "message" : "这个请求需要用户认证。" } }
我不知道发生了什么,我已经创建了访问令牌。
【问题讨论】:
标签: javascript php ajax spotify