我正在尝试使用 Spotify Web API 构建一个 Spotify 网络播放器。我在 Spotify 上注册了我的应用程序并将回调 URL 列入白名单。然后授权过程工作正常。我收到用于提出其他请求的令牌。但是当我尝试提出一个简单的当前播放请求时
https://developer.spotify.com/web-api/get-the-users-currently-playing-track/
我收到
Array ( [error] => Array ( [status] => 401 [message] => Permissions missing ) )
Run Code Online (Sandbox Code Playgroud)
PHP代码是:
session_start();
$req = $_SESSION['token_type'] . " " . $_SESSION['token'];
$headers_after_token = array(
"Accept: */*",
"Authorization: " . $req);
$url="https://api.spotify.com/v1/me/player/currently-playing";
echo "<br>REQ-currently-playing: ".$req."<br>";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers_after_token);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = json_decode(curl_exec($ch), true);
curl_close($ch);
echo "<br><br>";
print_r($response);
Run Code Online (Sandbox Code Playgroud)
在$_SESSION['token_type']作为API端点引用提到包含“承载”
https://developer.spotify.com/web-api/endpoint-reference/
在$_SESSION['token'] …