Skip to content

Fun with twitter api

December 28, 2009

After a tweet by mortenrovik I got intrigued to have a quick look at the Twitter api. I ended up with a quick and brutal php script to display the number of followers you have on your site. Here is the code snippet (php):

<?php
$doc = new DOMDocument();
$doc->load( 'http://twitter.com/followers/ids/eothred.xml' );
$items = $doc->getElementsByTagName( "id" );
$followers=0;
foreach( $items as $item ) {
$followers++;
}
// display the number of followers
print "Number of followers: ".$followers;
?>

Change “eothred” in the link with your own username. You can modify the print command in the last line as you see fit obviously… But then I realized how difficult it is to add php code into a blog entry (is it even possible?) I checked the script locally on my computer (php version 5.3.1), but as long as I cannot include php code in my blog.. Oh well.

Advertisements
No comments yet

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: