Я попытался добавить трек в совместный плейлист, это мой код для токена доступа
$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, «сообщение»: «Этот запрос требует аутентификации пользователя». } }
Я не знаю, что случилось, я создал токен доступа.