Get Twitter, Facebook And Feed Readers Count In ASP.NET

I am working on some web stuff these days and surfing around to look at some of the best web developer’s work around the web. As I was surfing I came across one of the most popular and reputed web tutorials site Nettus+. I am not going talking about any tutorial or article published on this site, but one thing that attracts my attention was the way they are displaying their followers count on twitter, facebook likes and RSS readers.

Nettuts+ Social Widget

This looks pretty cool and just out of curiosity I viewed the page source, hoping to find some script or API call which gets the count. But eventually I can’t found anything. For Twitter and Facebook I know that there is an API and therefore I can get the twitter followers and facebook like count but don’t know anything about the feed readers count. So I search the web get myself aware of the feedburner API. So let’s take a look at the code.

Get Twitter Followers Count

To get your twitter followers count, I am making a REST API call. This call will return XML string and then I am going to parse the received XML using LINQ. You just need to pass your twitter user name to get the followers count.

public string GetTwitterFollowersCount(string UserName)
{
            XDocument xdoc = XDocument.Load("http://api.twitter.com/1/users/show.xml?screen_name=" + UserName + "&include_entities=false");
            return (from item in xdoc.Descendants("user")
                    select item.Element("followers_count").Value).SingleOrDefault();
}

Get Facebook Likes Count

To get total Facebook likes count you need to remember that you have to use the URL of your page for e.g. http://www.facebook.com/audi or http://www.facebook.com/nettutsplus and not just the name of your page. Check out the code:

public string GetFacebookLikes(string FaceBookURL)
{
         string URL = "https://api.facebook.com/method/fql.query?query=select%20%20like_count,%20total_count,%20share_count,%20click_count%20from%20link_stat%20where%20url=%22" + FaceBookURL + "%22";
         XElement xdoc = null;
         XElement counts = null;
         xdoc = XElement.Load(URL);
 
         IEnumerable<XElement> total_Like_count =
             from elem in xdoc.Descendants()
             where elem.Name.LocalName == "like_count"
             select elem;
 
         counts = total_Like_count.First();
         string FBLikes = Convert.ToString(counts.Value);
         return FBLikes;
}

Get RSS Feed Readers Count

To get the RSS feed readers count you need to pass the complete URL of your feed URL for e.g. http://feeds.feedburner.com/MidnightProgrammer

public string GetFeedReadersCount(string url)
{
            XDocument xdoc = XDocument.Load("http://feedburner.google.com/api/awareness/1.0/GetFeedData?uri=" + url);
            return (from item in xdoc.Descendants("entry")
                    select item.Attribute("circulation").Value).SingleOrDefault();
}

This is it, now it all depends on the designer or developer how to get the stats and present it in a more attractive way. I am not a designer and this is why I am not putting any effort to do something like this to show you this thing in action. At present I am working on JQuery version of the above code, so people who are willing to show stats on their blogs or website which are different platforms. Till that time, try the above code with ASP.NET and let me know of this helps you out.

comments powered by Disqus