0

I'm trying to build a Web application that would enable an user to search for a song in the Spotify's database and if found automatically search for a music video pertaining to that track. To do that I figured I need to learn some basic Spotify API. I've researched Spotify's Web API and wanted to just test if I can get a json response from a simple query (following this documentation page).

curl -k -X GET "https://api.spotify.com/v1/search?q=tania%20bowra&type=artist"

Running this from the command prompt gives me the expected result. The problem starts when I want to get the same result from my test php page.

<?php 

 //instantiate an instance of cURL
 $curl = curl_init(); //returns a cURL resource
 
 $spotifyURL = 'https://api.spotify.com/v1/search?q=tania%20bowra&type=artist';
 curl_setopt ($curl, CURLOPT_URL, $spotifyURL);
 //send the request and save the response
 $response = curl_exec($curl);

 if($response){
 echo 'Success';
 }else{
 echo 'Failure';
 }
?> 

The page always displays 'Failure'. There is no json response. I'm an absolute beginner when it comes to PHP/cURL and Spotify WebAPI so I might be missing out on something really obvious. Any help would be greatly appreciated.

Thanks

1 Answers1

0

Turns out I needed to disable certificate warnings (stack overflow answer) just like I did in the command prompt with the -k modifier.

Adding curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); solved the issue

Community
  • 1
  • 1