Fetch twitter updates via PHP

XML, php Add comments
Satisfied with your knowledge? No! then spent 15 mins. every day on PHPCamp.net a knowledge sharing website for PHP community

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

Well if you liked it,then you can:


Grab my feed

OR

OR

Bookmark for future reference
  • Digg
  • del.icio.us
  • Facebook
  • Google
  • blogmarks
  • description
  • Faves
  • IndianPad
  • Live
  • MySpace
  • Slashdot
  • StumbleUpon
  • Technorati
  • TwitThis
  • LinkedIn
  • Linkter

8 Responses to “Fetch twitter updates via PHP”

  1. Ramankit Singh Says:

    nice idea dude….. :)

  2. Aman Says:

    Thanks mate..

  3. Ramankit Singh Says:

    cool article…………u rock dude….

  4. SeanJA Says:

    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.

  5. [Web] Says:

    [...] Fetch twitter updates via PHP [...]

  6. James Says:

    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?

  7. Checkout: send message from a PHP page using Twitter API at oneafrikan.com Says:

    [...] Fetch twitter updates via PHP http://blog.amanjain.com/2009/01/fetch-twitter-updates-via-php/ [...]

  8. Duncan Says:

    The reason you were getting that error is most likely because you have curly quotes - change all the double quotes to ’straight’ quotes

Leave a Reply

WP Theme & Icons by N.Design Studio. Indified by IndiBlogger.in.
Entries RSS Comments RSS Log in

Technology Top Blogs Technology Blogs - BlogCatalog Blog Directory Visit blogadda.com to discover Indian blogs blogarama - the blog directory