Counting Twitter Followers and Friends

by xearther ~ April 17th, 2009. Filed under: Code Lounge.

Expanding on the prior post, below is the simple code to display the number of Followers and Friends of any Twitter User. Just pass the User Name to the php file like so:

The browser will then display something like:

8 Friends

You are welcome to use the above URL. Just replace xearther with any Twitter User Name of your choosing. And like the prior post, this code does not require any password.

Here is the code behind followersfriends.php:

$username = trim(@$_GET[‘u’]);
$xmlfollowers = simplexml_load_file(“$username.xml“);
$xmlfriends = simplexml_load_file(“$username.xml“);

foreach($xmlfollowers->children() as $child)
echo “$x Followers<br>”;

foreach($xmlfriends->children() as $child)
echo “$x Friends<br>”;

I hope you find this interesting and somewhat useful.

On Sunday I will post the code that builds on the code above and synchronizes Friends to be exactly the same as Followers.

Comments are closed.