Php function to get the number of twitter followers

The following code snippet will fetch the number of twitter followers of a given twitter username

/*
	This function will fetch the number of twitter followers of a twitter id
	It works by fetching an xml page for the user's information
*/

function get_followers($twitter_id)
{
	$xml = file_get_contents('http://twitter.com/users/show.xml?screen_name='.$twitter_id);
	
	$s = simplexml_load_string($xml);
	
	$follower_count = $s->followers_count;
	
	return $follower_count;
}

/*
	Enter your twitter id here to test the code
*/
$twitter_id = 'linux';

echo "$twitter_id has ". get_followers($twitter_id) . ' twitter followers';






Last Updated On : 4th August 2012

Subscribe to get updates delivered to your inbox

2 Comments + Add Comment

  • The API used in this code does not exist anymore.

  • Good information here. I really enjoy reading them every day. I’ve learned a lot from them.

Leave a comment