Click to find out more about our Work
November 18th, 2008

Tutorial : Display no.of RSS Readers using Feedburner API and PHP (curl)

2 Comments

Most of you who have blogs/website might be aware of FeedBurner. Its a service which provides custom RSS Management tools like Analysing Web-Traffic, the number of readers subscribed to you blog etc. I too use Feedburner to help me keep track of my feeds and its readers. Although I love their service, I always found the FeedBurner Chicklet (It displays the number of readers subscribed to your RSS) to be a constraint, it isn`t that flexible i.e We can modify the color of the chicklet but not the chicklet it self. So I decided to create my own Chicklet to help me display the number of readers subscribed to my blog. (Although the number isn`t that big :P )

It Starts ! Feedburner API

Hmm..so where did I start…. Ahh ! The Feedburner API ofcourse. I wanted to know how to retrieve the number of Readers of a particular RSS feed as simple text.
http://code.google.com/apis/feedburner/awareness_api.html had the answer to my problem !

Current Basic Feed Awareness Data
https://feedburner.google.com/api/awareness/1.0/GetFeedData?uri=<feeduri>

where <feeduri> = your feedname i.e vmdtuts in my case

Sample Response
circulation – An approximate measure of the number of individuals for whom your feed has been requested in the 24 hour period described by date.

Thats what I was looking for !!. Now Since I have a way to access information about my RSS feeds, I had to think of a method to request the API url and retrieve the result using PHP (ofcourse).
Note : If you try to access the above URL with your feed address, you`ll see an XML output with all the relevant details about your feed !.

Thank You CURL – Here is the Code

We`ll use CURL to make a request to the above URL and retrieve the XML output.

$my_feed_url = "https://feedburner.google.com/api/awareness/1.0/GetFeedData?uri=yourfeedurl"; // yourfeedurl = vmdtuts in my case

$s_ch = curl_init(); //Initialize Curl
curl_setopt($s_ch, CURLOPT_RETURNTRANSFER, 1);//Set curl to return the data instead of printing it to the browser.
curl_setopt($s_ch, CURLOPT_URL, $my_feed_url); //Set the URL
$data = curl_exec($s_ch); //Execute the fetch
curl_close($s_ch); //Close the connection
$xml = new SimpleXMLElement($data);
$no_of_readers = $xml->feed->entry['circulation'];

echo $no_of_readers."Readers"; //Will display no of Readers

Voila There you have it. A Simple method to retrieve the number of readers who have subscribed to your RSS.

Tip : If you want to display the number of Readers in your Wordpress Blog. Just open up sidebar.php and insert the code anywhere where you want to display the number of readers.

2 Responses to “Tutorial : Display no.of RSS Readers using Feedburner API and PHP (curl)”

  1. kthxbai2u
    July 2, 2009 at 6:52 am

    Great code! I will be definatley using this code in one or more of my apps :)

  2. Napolux
    January 10, 2009 at 6:42 pm

    I’ve done the same trick using Flex & Adobe AIR. It’s already compatible with feeds moved to feedproxy.google.com ;)

    Check it out!

    http://www.napolux.com/2009/feedburner-counter-in-english.html

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code lang=""> <del datetime=""> <em> <i> <p> <q cite=""> <strike> <strong>