Want to display your (or maybe be someone else’s) public timeline using php? Ok, here’s the solution for it:
<?php
$username = “amanjain”;
$rssUrl = “http://twitter.com/statuses/user_timeline/$username.rss”;
$rss = @file_get_contents($rssUrl);
if($rss)
{
$xml = @simplexml_load_string($rss);
if($xml !== false)
{
foreach($xml->channel->item as $tweet)
{
echo $tweet->pubDate.”\n”;
echo substr($tweet->description,10).”\n\n”;
}
}
else
{
echo “Error: RSS file not valid!”;
}
}
else
{
echo “Error: RSS file not found, dude. Username invalid or requires authentication”;
}
?>
Find the script live here: http://blog.amanjain.com/twitter






















January 4th, 2009 at 6:54 am
nice idea dude…..
January 4th, 2009 at 7:15 am
Thanks mate..
January 4th, 2009 at 7:15 am
cool article…………u rock dude….
January 7th, 2009 at 9:52 am
Alternatively you could use the http://search.twitter.com/search.rss?q=username&@username if you just want things that are from and to that user.
January 14th, 2009 at 7:44 pm
[...] Fetch twitter updates via PHP [...]
February 13th, 2009 at 4:22 am
Thank you for this!!! But I have a problem, i’m very limited in PHP skill, I get this error:
“Parse error: syntax error, unexpected ‘:’ in /home/jamesca1/public_html/test.php on line 3″
Code for simple page with twitter output:
Twitter Test
channel->item as $tweet)
{
echo $tweet->pubDate.”\n”;
echo substr($tweet->description,10).”\n\n”;
}
}
else
{
echo “Error: RSS file not valid!”;
}
}
else
{
echo “Error: RSS file not found, dude. Username invalid or requires authentication”;
}
?>
What am I doing wrong?
February 18th, 2009 at 3:35 am
[...] Fetch twitter updates via PHP http://blog.amanjain.com/2009/01/fetch-twitter-updates-via-php/ [...]
March 26th, 2009 at 8:46 pm
The reason you were getting that error is most likely because you have curly quotes - change all the double quotes to ’straight’ quotes