I'm trying to get all of the user's playlists from spotify, but my code returns me error 401, This request requires authentication.
I have already got the Authorisation key which is set as $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.