Spotify 网络 API - 缺少 401 权限
Spotify web API - 401 Permissions missing
我正在尝试使用 Spotify 网络构建一个 Spotify 网络播放器 API。
我在 spotify 上注册了我的应用程序并将回调列入白名单 URL。
然后授权过程工作正常。我收到用于发出其他请求的令牌。
但是当我尝试发出一个简单的当前正在播放的请求时,
https://developer.spotify.com/web-api/get-the-users-currently-playing-track/
我收到了
Array ( [error] => Array ( [status] => 401 [message] => Permissions missing ) )
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);
$_SESSION['token_type']
包含 "Bearer",如 API 端点参考中所述
https://developer.spotify.com/web-api/endpoint-reference/
$_SESSION['token']
包含身份验证过程后检索到的令牌。
由于 echo "<br>REQ-currently-playing: ".$req."<br>";
两个变量的格式都很好,我可以看到设置了 2 个变量。
我正在使用 XAMPP v3.2.2 部署 php 页面。
为了能够获取当前播放,您需要在授权用户时添加范围user-read-currently-playing
and/or user-read-playback-state
。
有了这种授权,用户需要同意您的应用可以代表他们做什么。有些东西是默认包含的,但有些东西(就像这样)需要用户的额外权限。
如果您在文档中看到它说某个函数需要 "this and that" 范围,则需要将其添加到授权中。
我正在尝试使用 Spotify 网络构建一个 Spotify 网络播放器 API。 我在 spotify 上注册了我的应用程序并将回调列入白名单 URL。 然后授权过程工作正常。我收到用于发出其他请求的令牌。 但是当我尝试发出一个简单的当前正在播放的请求时,
https://developer.spotify.com/web-api/get-the-users-currently-playing-track/
我收到了
Array ( [error] => Array ( [status] => 401 [message] => Permissions missing ) )
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);
$_SESSION['token_type']
包含 "Bearer",如 API 端点参考中所述
https://developer.spotify.com/web-api/endpoint-reference/
$_SESSION['token']
包含身份验证过程后检索到的令牌。
由于 echo "<br>REQ-currently-playing: ".$req."<br>";
两个变量的格式都很好,我可以看到设置了 2 个变量。
我正在使用 XAMPP v3.2.2 部署 php 页面。
为了能够获取当前播放,您需要在授权用户时添加范围user-read-currently-playing
and/or user-read-playback-state
。
有了这种授权,用户需要同意您的应用可以代表他们做什么。有些东西是默认包含的,但有些东西(就像这样)需要用户的额外权限。
如果您在文档中看到它说某个函数需要 "this and that" 范围,则需要将其添加到授权中。