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

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

6 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.

This website uses IntenseDebate comments, but they are not currently loaded because either your browser doesn't support JavaScript, or they didn't load fast enough.

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

  1. Ruben
    February 20, 2010 at 3:13 am

    It's Working ! You must have an account with feedburner and activateth " Awareness API " …
    Great Tuto, thanks !

  2. Alek
    November 15, 2009 at 3:46 pm

    I dont think this is working my friend .. It gets stuck in the fetching loop.

  3. kthxbai2u
    October 29, 2009 at 9:35 am

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

  4. Rubira
    October 21, 2009 at 2:15 am

    :( “Fatal error: Uncaught exception ‘Exception’ with message ‘String could not be parsed as XML’ “

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

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

  6. 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>