views:

15

answers:

1

I'm currently using this code to get the number of subscribers to my blog:

$whaturl="http://api.feedburner.com/awareness/1.0/GetFeedData?uri=http://feeds.feedburner.com/DesignDeluge"; 
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $whaturl);
$data = curl_exec($ch);
curl_close($ch);
$xml = new SimpleXMLElement($data); 
$fb = $xml->feed->entry['circulation'];

but when I echo $fb it doesn't work (the whole file that $fb is being echoed on doesn't appear). Any ideas on why this isn't working?

+1  A: 

If you take a look at $data before trying to load it with SimpleXMLElement, you'll see it contains the following portion of HTML code :

<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="http://feedburner.google.com/awareness/1.0/GetFeedData?uri=http://feeds.feedburner.com/DesignDeluge"&gt;here&lt;/A&gt;.
</BODY></HTML>

So, there's no way you'll find what you're looking for in there ;-)


A solution could be to use the CURLOPT_FOLLOWLOCATION option (see curl_setopt), so curl follows redirections...

... But this doesn't seem to work either.


Actually, when I try to load the URL that's given in the portion of HTML code I posted earlier :

http://feedburner.google.com/awareness/1.0/GetFeedData?uri=http://feeds.feedburner.com/DesignDeluge

I only get the following XML as return :

<?xml version="1.0" encoding="utf-8" ?>
<rsp stat="fail">
    <err code="2" msg="This feed does not permit Awareness API access" />
</rsp>


Are you sure you are using the right URLs / feeds ?

Pascal MARTIN
Ah, it turns out two things were wrong: the tutorial I was following was out-dated so the URL was wrong and I also had to enable access to the API myself. Thanks!
WillyG
You're welcome :-) Glad you found out what was causing the problems :-)
Pascal MARTIN