Deluxe Blog Tips About Projects

Get Total Twitter Followers With jQuery

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

Subscribe to the Newsletter

Subscribe to get my latest content by email. I won't send you spam. Unsubscribe at any time.