Php function to get the number of twitter followers

By | August 4, 2012

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

Related Post






2 thoughts on “Php function to get the number of twitter followers

Leave a Reply

Your email address will not be published. Required fields are marked *