Spotify Metadata API
https://api.spotify.com/v1/search?q=Maycon+%26+Vinicius+&limit=1&type=artist
Error
{
“error” : {
“status” : 401,
“message” : “No token provided”
}
}
Spotify Metadata API is deprecated. Spotify now have new Web API with Authorization Token to take advantage of metadata for registered applications.
Registering Your Spotify Application
Register your Application here https://developer.spotify.com/web-api/tutorial/ and get Client ID and Secret Key
<?php /* Spotify Application Client ID and Secret Key */ $client_id = '[Client ID]'; $client_secret = '[Secret Key]'; /* Get Spotify Authorization Token */ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://accounts.spotify.com/api/token' ); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 ); curl_setopt($ch, CURLOPT_POST, 1 ); curl_setopt($ch, CURLOPT_POSTFIELDS, 'grant_type=client_credentials' ); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Basic '.base64_encode($client_id.':'.$client_secret))); $result=curl_exec($ch); $json = json_decode($result, true); /* Get Spotify Artist Photo */ echo "<pre>"; exec('curl -i "https://api.spotify.com/v1/search?q=Maycon+%26+Vinicius+&limit=1&type=artist" -H "Accept: application/json" -H "Authorization: Bearer '.$json['access_token'].'" -H "Content-Type: application/json" 2>&1', $pp); echo implode("\r\n", $pp); ?>
Ajax Call
jQuery.ajax({ url: 'https://api.spotify.com/v1/search?q=Maycon+%26+Vinicius+&limit=1&type=artist', headers: { "Authorization": "Bearer <?php echo $json['access_token']; ?>", "Accept": "application/json; charset=utf-8", "Content-Type": "application/json; charset=utf-8" }, success: function(response) { console.log(response); console.log(response.artists.items[0].images[0].url); } });
Spotify Interactive API Console
The Spotify Web API Console lets you explore the endpoints through an easy-to-use interface.
https://developer.spotify.com/web-api/console/