Question

I'm using Deezer APIs

$xml = simplexml_load_file('http://api.deezer.com/2.0//search/artist/?q=eminem&index=0&nb_items=1&output=xml');

var_dump($xml);

$xml = simplexml_load_file('http://api.deezer.com/2.0/artist/393/top/&output=xml');

var_dump($xml);

The first call works in the same way both on my local machine (Mac PHP 5.3.15) and online on a dream-host server (PHP 5.3.13), the second call works on my local machine, reporting all 5 track objects, but not on-line, where I just get

object(SimpleXMLElement)#4 (2) { 
 ["data"]=> object(SimpleXMLElement)#1 (0) { } 
 ["total"]=> object(SimpleXMLElement)#3 (0) { } 
}

It seems to me very weird, do you have any clue?

Thanks

Was it helpful?

Solution

Deezer use geolocation for Artist Request.

So, if your server is geolocated in US for example, the first request have the same result between local and online but de second one (http://api.deezer.com/2.0/artist/393/top/&output=xml) don't have the same result local/online.

Request with FR Ip :

<?xml version="1.0" encoding="utf-8"?><root><data><track><id><![CDATA[2114267]]></id><readable><![CDATA[1]]></readable><title><![CDATA[My Life]]></title><link><![CDATA[http://www.deezer.com/track/2114267]]></link><duration><![CDATA[321]]></duration><rank><![CDATA[674751]]></rank><preview><![CDATA[http://cdn-preview-2.deezer.com/stream/2ecb4b24f51cdbfdaea89630f1978529-0.mp3]]></preview><artist><id><![CDATA[393]]></id><name><![CDATA[The Game]]></name></artist><type><![CDATA[track]]></type></track><track><id><![CDATA[2307182]]></id><readable><![CDATA[1]]></readable><title><![CDATA[Hate It Or Love It]]></title><link><![CDATA[http://www.deezer.com/track/2307182]]></link><duration><![CDATA[207]]></duration><rank><![CDATA[654207]]></rank><preview><![CDATA[http://cdn-preview-3.deezer.com/stream/393350005d03712abc9adfbe2bcfe2d3-0.mp3]]></preview><artist><id><![CDATA[393]]></id><name><![CDATA[The Game]]></name></artist><type><![CDATA[track]]></type></track><track><id><![CDATA[2294433]]></id><readable><![CDATA[1]]></readable><title><![CDATA[How We Do]]></title><link><![CDATA[http://www.deezer.com/track/2294433]]></link><duration><![CDATA[235]]></duration><rank><![CDATA[610398]]></rank><preview><![CDATA[http://cdn-preview-c.deezer.com/stream/c3683a1fc1899c9d1b128b222d0e080f-1.mp3]]></preview><artist><id><![CDATA[393]]></id><name><![CDATA[The Game]]></name></artist><type><![CDATA[track]]></type></track><track><id><![CDATA[62751648]]></id><readable><![CDATA[1]]></readable><title><![CDATA[Ali Bomaye]]></title><link><![CDATA[http://www.deezer.com/track/62751648]]></link><duration><![CDATA[373]]></duration><rank><![CDATA[571988]]></rank><preview><![CDATA[http://cdn-preview-1.deezer.com/stream/1bb2606c722235eeecb2b1caa039f5c1-0.mp3]]></preview><artist><id><![CDATA[393]]></id><name><![CDATA[The Game]]></name></artist><type><![CDATA[track]]></type></track><track><id><![CDATA[61571949]]></id><readable><![CDATA[1]]></readable><title><![CDATA[Celebration]]></title><link><![CDATA[http://www.deezer.com/track/61571949]]></link><duration><![CDATA[290]]></duration><rank><![CDATA[559639]]></rank><preview><![CDATA[http://cdn-preview-f.deezer.com/stream/f1f535359bd60ce3ec77d59fcfda4ebd-1.mp3]]></preview><artist><id><![CDATA[393]]></id><name><![CDATA[The Game]]></name></artist><type><![CDATA[track]]></type></track></data><total><![CDATA[5]]></total></root>

The same request with US location :

<?xml version="1.0" encoding="utf-8"?><root><data></data><total><![CDATA[0]]></total></root>

To complete the answer. You can change Geolocation of your request (and have result from US Server) with access_token of user located in non-restricted country because when you request the deezer api with access_token, the api will use the user country and not the server country.

To get an access token from user : http://developers.deezer.com/api/oauth

Don't forget on each request when you want to use the User geolocation to add this :

?access_token=XXXXX

EDIT : I am part of the deezer team.

OTHER TIPS

if you want to access xml by http protocol you will need to set allow_url_fopen ON in php.ini or

ini_set('allow_url_fopen ','ON');

in your code. or you can also do this if you are using php version <5

$temp = file_get_contents($url);
 $XmlObj = simplexml_load_string($temp); 

try:

$xml = simplexml_load_file('http://api.deezer.com/2.0/artist/393/top/?output=xml');

(i.e. change the '&' to '?')

This may or may not be the problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top