jQuery Get Total Twitter Followers

There are many snippets on the Internet that show you how to get total Twitter followers of an user, most of them are written in PHP or other server-side script languages. But do you know that we can do that with only pure Javascript by using ajax in jQuery?

Here is the snippet, it’s very simple:

<strong>Rilwis</strong> has <span id="followers"></span> followers.

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
    $.ajax({
        url: 'http://api.twitter.com/1/users/show.json',
        data: {screen_name: 'rilwis'},
        dataType: 'jsonp',
        success: function(data) {
            $('#followers').html(data.followers_count);
        }
    });
});
</script>

Replace the screen_name variable to your Twitter username.

We use the jQuery library from Google CDN and Twitter API to make an ajax call to get user’s details. If the request is success, we update the DOM to show total followers.

View demo

11 Comments

  1. This information became obsolete since Twitter API 1.1.

  2. Gurubaksh SIngh

    August 4, 2014 at 11:51 AM

    Not working at all

  3. thanks for posting how to get following numbers

  4. Great stuff. Have you ever tried to get the total number of tweets made by a user to display? Something I have been working on but to no avail as of yet…

  5. Nice Collection..!

  6. Great post Rilwis! Is there any way to use multiple usernames within one script? And define a separate span class for them?

    Thanks!

  7. Hi,
    Thanks for sharing. Can I post your article on my website here http://www.sabbirh.com

    Please let me know.
    Thanks
    Sabbir

  8. Hey thanks, It worked for me. If you change “http” to “https” in the url, it will work much faster.

  9. I’ve been looking for this all morning. PERFECT!

  10. It works, thanks.

Leave a Reply

Your email address will not be published.