Displaying Your FeedBurner Subscriber Count Anywhere - PHP Coding Tutorial ln -s brandontreb.log

If you are a serious blogger (and I'm sure you are), you probably track your RSS subscribers with FeedBurner. If you don't, you should be. One thing that has always bugged me about FeedBurner is if you ever wanted to display the number of subscribers on your blog, you were stuck using their image. The image looks like this:
I'm sure you have seen this logo everywhere. Well, not too many people know it, but FeedBurner actually has a very simple API that allows you to just get the subscriber count so you can display it however you would like.
So rather than being limited to this boring icon, you can display your live subscriber count anywhere on your blog. If you are feeling adventurous, you could even super impose it on to your own custom image using the GD library (tutorial to come if sufficient interest, post in the comments if you would like to see it).
Let's get started...
1. Activate the Awareness API Inside Of Feedburner
Log in to FeedBurner. Click the Publicize tab and the click Awareness API. Finally, click Activate. The service is now enabled.
2. Write The PHP Code To Interface With FeedBurner
There is a lot of data that you could potentially get from FeedBurner, but the code below will just show you how to get your subscriber count.
All you need to do is make a simple GET request using CURL to the URL https://feedburner.google.com/api/awareness/1.0/GetFeedData?uri=brandontreb . Of course replacing brandontreb with your feed's name.
<?php
$url = "https://feedburner.google.com/api/awareness/1.0/GetFeedData?uri=brandontreb";
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
$data = curl_exec($ch);
curl_close($ch);
if ($data) {
echo $data;
preg_match('/circulation=\"([0-9]+)\"/',$data, $matches);
if ($matches[1] != 0) {
$subscriberCount = $matches[1];
}
}
echo "Join the other $subscriberCount people and subscriber to my RSS feed."
?>
blog comments powered by Disqus
