doulachan8217 2016-12-28 11:17
浏览 49
已采纳

此请求需要身份验证。 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.

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.

  • 写回答

1条回答 默认 最新

  • duano3557 2016-12-28 12:22
    关注

    Your code seems ok as per the spotify documentation. You can consider the following two to adjust your code.

    1. Again double check the api key that is a valid.
    2. There is an extra / at the end of the endpoint playlist/. It has a chance to cause the issue. You can try removing that / after playlist.
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100