How To: Display Twitter Followers List On Your Blog

How To: Display Twitter Followers List On Your Blog

Almost a year ago I’ve shared a simple script to display your Twitter followers count on your blog or website. But how to display followers list?. Have you ever tried? Today I'd like to share another simple PHP script to display your Twitter followers. This code is very simple. I think it'll be very helpful for you. Let’s get started

Step 1: Grab Followers List

The following PHP function grabs data from Twitter API http://api.twitter.com/1/statuses/followers.format in JSON format then it’ll decode the JSON format and displays your follower’s name, thumbnail, and username.

<?php 
function followers_list($user_name='')
{
if($user_name)
{
$data = file_get_contents('http://api.twitter.com/1/statuses/followers/'.$user_name.'.json&');
$response = json_decode($data,true);
foreach($response as $followers)
{
$name = $followers['name'];
$thumb_img = $followers['profile_image_url'];
$screen_name = $followers['screen_name'];
echo '<img src="'.$thumb_img.'" alt="'.$name.'" width="30" height="30" border="0" />
<a title="'.$name.'" href="http://www.twitter.com/'.$screen_name.'"><strong>'.$name.'</strong>
</a>
<small>@'.$screen_name.'</small>';
}
}
}
?>

This is the main function. Copy and paste it your common functions file like config.php, main_functions.php, engin.php, etc.. If you are a WordPress blogger open functions.php, paste this script and save the file.

Step 2: Display Followers List

To display your follower’s list, simply call this function wherever you want to display your Twitter followers list. for eg:

My Twitter Followers:<?php followers_list('lineshjose');?>

It’s very simple, right?

Note: This API returns 100 followers at a time. That means you can only list a maximum of 100 followers. Please click the following link to know more about Twitter GET statuses/followers API.