Search code examples
jqueryfacebooktwitter

How to get total followers count of Twitter and Facebook using jQuery


Today I visited this blog, Blogger Ever and I saw a social counter. I do not want all of them just Twitter and Facebook follower count and their total. I know using Facebook Graph API I can extract likes like done in this fiddle. Just want to get twitter followers count using jQuery, anyone can help?

var url = 'http://graph.facebook.com/google';
$.getJSON(url, function(data){
    $('body').append(data.likes);
});

Solution

  • for twitter and total of their both. First go to Twitter Counter it is the tool that gives stats of your twitter account and it also have an API. register your API Key from this page. After getting API key, you need to know your twitter id for that go to this site. After getting twitter id, just replace your twitter id and api key just replace in this fiddle and click run you will get your social counter. jQUERY

      var apikey='REPLACE_WITH_YOUR_API';
         var twitterid='YOUR_TWITTER_ID';
    $.when(
    
        $.ajax({
            type: "GET",
            dataType: "jsonp",
            url: "http://api.twittercounter.com/?twitter_id="+twitterid+"&apikey="+apikey+"&output=JSONP&callback=getcount",
            success: function (data) {
                var twitterfollowcount = data.followers_current;
                $(".twitter").html(twitterfollowcount);
            }
        }),$.ajax({
            type: "GET",
            dataType: "json",
            url: "http://graph.facebook.com/bloggerever",
            success: function (data) {
                var facebookfollowcount = data.likes;
                $(".facebook").html(facebookfollowcount);
            }
        })  
        ).done(function (twitter,facebook) {
            var total =twitter[0].followers_current+facebook[0].likes;
    
            $('.total').append(total);
        });
    

    Note Twitter api used in the code above was not official by Twitter, now they have removed it, therefore twitter wont work.