[英]This request requires authentication. Spotify API
I'm trying to get all of the user's playlists from spotify, but my code returns me error 401, This request requires authentication. 我试图从Spotify获取所有用户的播放列表,但是我的代码向我返回错误401,该请求需要身份验证。
I have already got the Authorisation key which is set as $key
. 我已经有设置为$key
的授权$key
。 Here's my code. 这是我的代码。
$key='*KEYHERE*';
$userid='acorn3';
$ch = curl_init();
$url = "https://api.spotify.com/v1/users/" . $userid . "/playlists/";
echo $url . "<br>";
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch,CURLOPT_URL, $url);
$header = array('Accept: application/json', 'Authorization: Bearer '.$key);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
$result = curl_exec($ch);
if($result === false)
{
echo "Error Number:".curl_errno($ch)."<br>";
echo "Error String:".curl_error($ch);
}
curl_close($ch);
I think I'm missing something simple here, but I can't see what. 我想这里缺少一些简单的东西,但是我看不到。
Your code seems ok as per the spotify documentation . 根据Spotify文档,您的代码似乎还可以。 You can consider the following two to adjust your code. 您可以考虑以下两种方法来调整代码。
/
at the end of the endpoint playlist/
. 有一个额外的/
在端点结束playlist/
。 It has a chance to cause the issue. 有机会导致此问题。 You can try removing that /
after playlist. 您可以尝试在播放列表后删除该/
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.