Getting and parsing the Spotify Web API JSON with PHP

My aim is getting the album and its cover image with a given string like "Artist Name - Song Name". For that, I use Spotify Web API and I guess it doesn't require OAuth for these kinds of requests.

$ch=curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.spotify.com/v1/search?q=".$query."&type=track");
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
$data=curl_exec($ch);
curl_close($ch);
echo $data;

If you click the following link, you can get the JSON but this request returns me an error page. I've tried with Ajax as well but nothing changed. Can somebody help me about that?


在将它发送给Spotify之前,您应该先对您的查询进行urlencode() ,否则您将收到400 Bad Request响应。

链接地址: http://www.djcxy.com/p/55574.html

上一篇: 无法遍历Spotify API搜索中的(实际)结果

下一篇: 使用PHP获取和解析Spotify Web API JSON