Twitter PHP and SimpleXML feed
Just like the Google Charts API the Twitter API can be super simple. Twitter uses a few different XML feeds to send and receive data from a given user, some feeds require a user name and password supplied through Curl but a few are publicly available to all.
This example will use the built in SimpleXML functions which come with PHP5, this is a much faster and easier way to using alternative readers such as simplePie or anything else you might come across. As far as it goes I don’t think SimpleXML gets enough coverage so I am happy to put it to some use for this example.
Keeping it basic
$user = ‘adi182′;
echo ‘<a href=”http://www.twitter.com/’.$user.’”>Follow ‘.$user.’</a><br />’;
$xml = simplexml_load_file(“http://search.twitter.com/search.atom?q=from:”.$user.”&rpp=5″);
foreach($xml->entry as $tweet)
{
echo $tweet->title. “<br />”;
}
?>
So there you have it, the super simple example on putting a Twiter feed on your website.
Recent Comments