Sep032011
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: 'http://facebook.com/audi' });
$("#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 every time 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: jquery.SocialCounter.zip (889.00 bytes)



tasmimy
Oct 4, 2011 -
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
Oct 6, 2011 -
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
Nov 8, 2011 -
Is this plugin available for customization? I would like to fork it on Github to add social sites like Tumblr, Google+, LinkedIn, etc.
Prashant
Nov 9, 2011 -
Yes, it is available for customization. At the moment I am working on the Google+ counts.
rhys
Nov 10, 2011 -
Can you track the amount of tweets generated via tweet button?
Prashant
Nov 10, 2011 -
I don’t know….but there will be a way out using twitter API. Will look into it for sure.
Yoba
Nov 16, 2011 -
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
Nov 22, 2011 -
Thanks for this script!
Do you know how to get the facebook friends count instead of the facebook likes?
Prashant
Nov 22, 2011 -
@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: https://api.facebook.com/method/fql.query?query=select 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
Nov 22, 2011 -
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 = ‘https://api.facebook.com/method/fql.query?query=select friend_count from user where uid=’ + options.UName + ‘&format=json&callback=?’;
$.getJSON(Facebookurl, function (Count) {
$(selector).html(Count[0].friend_count);
});
}
Prashant
Nov 23, 2011 -
Thanks for sharing Jan
Counter for site
Mar 9, 2012 -
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
Mar 9, 2012 -
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 http://www.tomanthony.co.uk/…/
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("clients6.google.com/rpc;, options);
var results = JSON.parse(response.getContentText());
return results.result.metadata.globalCounts.count;
} catch(e){
}
var err = "-";
return err;
}