Php Spotify错误代码403-此请求需要用户身份验证

Php Spotify错误代码403-此请求需要用户身份验证,php,curl,spotify,Php,Curl,Spotify,我想通过php将曲目添加到我的私人Spotify播放列表中,但我没有完成。我总是收到错误信息 错误代码403-此请求需要用户身份验证 我不是spotify api的高手。有人能帮我吗?这是我的代码: <?php error_reporting(E_ALL); $url = 'https://accounts.spotify.com/api/token'; $method = 'POST'; $credentials = "Client ID:Client Secret"; $heade

我想通过php将曲目添加到我的私人Spotify播放列表中,但我没有完成。我总是收到错误信息

错误代码403-此请求需要用户身份验证

我不是spotify api的高手。有人能帮我吗?这是我的代码:

<?php
error_reporting(E_ALL);
$url = 'https://accounts.spotify.com/api/token';
$method = 'POST';

$credentials = "Client ID:Client Secret";

$headers = array(
        "Accept: */*",
        "Content-Type: application/x-www-form-urlencoded",
        "Authorization: Basic " . base64_encode($credentials));
$data = 'grant_type=client_credentials';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response_1 = curl_exec($ch);

curl_close($ch);

$response_1 = json_decode($response_1, true);
var_dump($response_1);

$token = $response_1['access_token'];
echo $token."<br>";

$headers_2 = array(
        "Accept: application/json",
        "Content-Type: application/x-www-form-urlencoded",
        ('Authorization: Bearer ' . $token));

$url_2 =  'https://api.spotify.com/v1/users/example/playlists/playlist_example_id/tracks';
$postargs = '?uris=spotify%3Atrack%3A4xwB7i0OMsmYlQGGbtJllv';

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url_2);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers_2);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postargs);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response_2 = curl_exec($ch);

curl_close($ch);

$response_2 = json_decode($response_2, true);
var_dump($response_2);

你在哪里找到连接API spotify的知识?我建议你使用/查看我的代码,因为没有办法编辑我的代码使其工作?@SvenJanning错误消息是自我解释的,不是吗?