Social Counter: JQuery Plugin To Get Twitter, Facebook And Feed Readers Count

2. September 2011 16:53

API ASP.NET Jquery Web  13 Comments

Appending my previous post, I have created a plugin in JQuery to get twitter followers count, facebook likes and feed readers count. In my previous post, I have shown a way to get the counts in ASP.NET and I have created this plugin so that everyone can use and show counts on their blogs or site.
To get started add the two javascript files, one is the jquery file and the other one is the plugin file.
<script type="text/javascript" src="Scripts/jquery-1.4.1.js"></script>
<script src="Scripts/jquery.SocialCounter.js" type="text/javascript"></script>
Before I proceed to show you how to get it done, I should explain a bit about my small plugin. This plugin accepts 2 parameters:
  • SocialSite: Name of the social site like Twitter, Facebook and Feeds (case-sensitive).
  • UName: This options holds the user name or the facebook URL or the feed reader URL or the user name.
Now it's all on the developer/designer where he wants to show the counter. I have set 3 divs on my page with ID. It is not at all necessary to use divs, you can use whatever you want. To get the counts I will do the following on the document.ready function.
$(document).ready(function () {
            $("#tweet").SocialCounter({ SocialSite: 'Twitter', UName: 'prashantmx' });
            $("#FBLikes").SocialCounter({ SocialSite: 'Facebook', UName: '' });
            $("#FeedReader").SocialCounter({ SocialSite: 'Feeds', UName: 'Midnightprogrammer' });

Just for your information, Feed Burner API has been deprecated by Google but they have also made sure that the current working of the feedburner would not be affected. I don't know if this is the reason behind this, but everytime I try to get my feed readers count I get 0. I think this is for time being and will be back on track soon.

Download: (889.00 bytes)

Currently rated 4.0 by 11 people

Comments (13)

tasmimy tasmimy
10/4/2011 4:27:22 AM #

hey thanks for this script i'm sorry but i'm not good at js can u tell me how to display the number of the followers ?

prashant prashant
10/6/2011 12:23:42 PM #

In an HTML page create a DIV and set it ID to anything you like. I have set it to "tweet" in my case. Once you do that get the above script on the page and you are done.

betacar betacar
11/8/2011 6:04:33 AM #

Is this plugin available for customization? I would like to fork it on Github to add social sites like Tumblr, Google+, LinkedIn, etc.

Prashant Prashant
11/9/2011 9:49:06 AM #

Yes, it is available for customization. At the moment I am working on the Google+ counts.

rhys rhys
11/9/2011 3:14:09 PM #

Can you track the amount of tweets generated via tweet button?

Prashant Prashant
11/9/2011 8:30:41 PM #

I don't know....but there will be a way out using twitter API. Will look into it for sure. :)

Yoba Yoba
11/15/2011 10:18:18 PM #

Thanks for the info. Ive integrated another solution for twitter feed on my site but i think this method is far superior. Thankyou once again

Jan Jan
11/21/2011 3:20:22 PM #

Thanks for this script! Do you know how to get the facebook friends count instead of the facebook likes?

Prashant Prashant
11/21/2011 9:21:54 PM #

@Jan: Thanks for asking. I will update the plugin soon now. And to get the facebook friend's count you need to pass/get the facebook userid which is a long number. FQL you need to use is: friend_count from user where uid=1314789720&format=xml When you are using the aboe with jquery use change/append the URL with [b]&format=json&callback=?[/b] hope this helps.

Jan Jan
11/22/2011 2:05:27 PM #

Thanks again. It worked, here the complete code for whose interested: // Gets Facebook friends, UName must be the uid of Facebook account. if (options.SocialSite == "Facebook") { var Facebookurl = ' friend_count from user where uid=' + options.UName + '&format=json&callback=?'; $.getJSON(Facebookurl, function (Count) { $(selector).html(Count[0].friend_count); }); }

Prashant Prashant
11/23/2011 10:39:17 AM #

Thanks for sharing Jan :)

Counter for site Counter for site
3/8/2012 10:26:09 PM #

Hey Prashant thanks for sharing this script.It is really helpful.You told that you were working on Google+ counts.Have you done with it.i am waiting for that script.

prashant prashant
3/9/2012 10:43:53 AM #

Yes, I do have the script with me, but to be honest I didn't wrote this script. I found it somewhere on the web. I don't have the original URL with me from where I got this script, but I hope the below script will help you. function getPlusones(url){ // from try{ var options = { "method" : "post", "contentType" : "application/json", "payload" : '{"method":"pos.plusones.get","id":"p","params":{"nolog":true,"id":"'+url+'","source":"widget","userId":"@viewer","groupId":"@self"},"jsonrpc":"2.0","key":"p", "apiVersion":"v1"}' }; var response = UrlFetchApp.fetch(";, options); var results = JSON.parse(response.getContentText()); return results.result.metadata.globalCounts.count; } catch(e){ } var err = "-"; return err; }

Add Comment

Visit to discover Indian blogs Computers Blogs