cURL PHP vs cmd

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';
 }
?> 

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

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

上一篇: Spoitfy和Echo Nest API不匹配,如何解决?

下一篇: cURL PHP vs cmd