0

I am using Alexa API in PHP to get ranking of websites. The API was working pretty fine few days ago but yesterday it suddenly stops working. The API seems giving me NO wanted output but only error.

My work is in context to the post Fetching Alexa data. I have some doubt that we might have run out of given limit (25K/day but not sure; I heard it somewhere else). But I am also suspecting that we can not consume such huge number of requests.

The API code is working on my localhost without any issue. So I guess Amazon/Alexa might have blocked my live server IP. Can they do? What are other alternatives to use Alexa API? Worst thing here is that there is no docs available on net at the moment. How can I make it working again on my live server?

My API code is given below:

// Get Alexa Data       
$url = "http://data.alexa.com/data?cli=10&dat=snbamz&url=" . $domain;
$response = simplexml_load_file($url);

// If you don't know when/where <POPULARITY> may be, you should use XPath to find it
//$popularity = $response->xpath("//SD/POPULARITY")[0];
// It will return a list of SimpleXMLElements,
$response_array = $response->xpath("//SD[POPULARITY]")[0];

$alexa = json_decode(json_encode($response_array), true);

echo "<pre>";
print_r($alexa);
echo "</pre>";

$global_rank = isset($alexa['POPULARITY']['@attributes']['TEXT']) ? number_format($alexa['POPULARITY']['@attributes']['TEXT']) : "N/A";
$country_rank = isset($alexa['COUNTRY']['@attributes']['RANK']) ? number_format($alexa['COUNTRY']['@attributes']['RANK']) : "N/A";
$country = isset($alexa['COUNTRY']['@attributes']['NAME']) ? $alexa['COUNTRY']['@attributes']['NAME'] : "N/A";

I am getting only "N/A" along with Notice: Undefined offset: 0 in...

Sachin
  • 1,646
  • 3
  • 22
  • 59
  • If you can share the whole error message, that might show which variable is having an offset zero accessed which doesn't exist? My guess is that $response_array can be empty in some situations – Lorna Mitchell Jul 11 '18 at 07:19
  • you can check on https://aws.amazon.com/awis/ – Mahesh Hegde Jul 11 '18 at 07:29
  • @MaheshHegde not easy to follow. Very confusing. Not described in liquid understandable way. – Sachin Jul 11 '18 at 17:43
  • @LornaMitchell error message is for `$response->xpath("//SD[POPULARITY]")[0]` – Sachin Jul 11 '18 at 17:44
  • Right. So what's in $response? Something that the xpath will match? My guess (without much info) is that there are situations where there isn't any matching data. It might be good to check that $response->xpath got some results before you access them. – Lorna Mitchell Jul 12 '18 at 09:01
  • it is an empty array – Sachin Jul 17 '18 at 16:09

0 Answers0