Get number of RSS subscribers and twitter followers in ASP.NET

I've seen so many Wordpress blogs that have nicely styled number of RSS subscribers and Twitter followers, but almost none ASP.NET-based blog engines. I am still using a default RSS subscriber counter provided by Feedburner which is, let's face it, ugly and boring, but that will change soon. Here is a simple and quick way to get your numbers in ASP.NET

RSS Subscribers

You can use FeedBurner Awereness API to get all the information you need. By calling the URL below and passing your FeedBurner username, you will get the an XML document with some information.

XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load("https://feedburner.google.com/api/awareness/1.0/GetFeedData?uri=jankoatwarpspeed");

This document looks like the exemple below. Circulation attribute of entry element is actuall number of your followers.

<?xml version="1.0" encoding="UTF-8"?>
<rsp stat="ok">
    <feed id="4phmc8tprfr2ev14294rmu32d4" uri="JankoAtWarpSpeed">
        <entry date="2009-11-23" circulation="6313" hits="17152" downloads="0" reach="147" />
    </feed>
</rsp>

So, to get this number, just find all entry elements, get the first one (and the only one), and read its circulation attribute.

XmlNodeList subscribers = xmlDoc.GetElementsByTagName("entry");
Response.Write(subscribers[0].Attributes["circulation"].Value);

Twitter followers

Similar to previous example, you can get needed information in XML format using Twitter API. A list of your followers is located in ids.xml. Results returned from API will look like the code below.

<?xml version="1.0" encoding="UTF-8"?> 
<id_list>
     <ids>
          <id>30592818</id>
          <id>21249843</id>
          ... truncated ...
     </ids>
     ...
</id_list>

Logically, all you have to do is to count the number of id's in the list.

XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load("http://twitter.com/followers/ids.xml?screen_name=jankowarpspeed");
XmlNodeList twitterList = xmlDoc.GetElementsByTagName("id");
Response.Write(twitterList.Count.ToString());

Conclusion

Normally you wouldn't use response.write and you might consider doing this with LINQ, but you got the point. So, BlogEngine users (including myself) and others, no more excuses for that ugly counters. 

More articles in Blog archive or elsewhere
Advertisement

5 Comment(s)

Kevin Babcock

Kevin Babcock 25 Nov 2009 #

Sounds like we need a BlogEngine plugin for better feed/Twitter counters!

Kris

Kris 02 Dec 2009 #

Very cool... will have to update my websites soon with this info. Now just need to create a better looking counter for them both.

James Avory

James Avory 03 Dec 2009 #

I think that changes are desired in this case. RSS is one of the most important things in blogging business and still one of the most popular ways of increasing traffic on site. Combining those with Twitter is just another good idea of making your posts more and more popular.

SJL Web Design

SJL Web Design 18 Jan 2010 #

Thanks for this Janko, I'm fairly new to ASP so this will be a good practice

felipe saavedra

felipe saavedra 11 Feb 2010 #

muchas gracias, me servirá mucho

saludos,
Felipe...

Comments are closed
via Ad Packs
9292