Get Twitter Followers From Twitter XML

As of March 5th 2013 this technique will not work anymore as this uses the old Twitter API, to learn how to use the new Twitter API have a look at this tutorial.

Using The New Twitter API V1.1

Twitter XML

Use the twitter to access your account or any account and return the number of followers you have. Many websites like to do this so that they can show how popular they are on Twitter hoping this will encourage more people to follow them.

Below is a small PHP snippet which will access a piece of XML for your account and grab your followers count so you can display this on your website.

As this snippet is getting XML about your profile it will also return lots more data which you can use the same approach to get certain data from the XML.

function get_followers($twitter_id){
	$xml=file_get_contents('http://twitter.com/users/show.xml?screen_name='.$twitter_id);
	if (preg_match('/followers_count>(.*)</',$xml,$match)!=0) {
		$tw['count'] = $match[1];
	}

	return $tw['count'];
}

Advertise here 50% Off

Comment