/ Published in: PHP
A simple PHP function for fetching tweets. Just provide your Twitter screen name and how many tweets you want and that is it. The function returns a simplified result set because you rarely need all the stuff that the Twitter API throws your way. If you need everything then just put FALSE as the last argument.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function myTweets($screenname, $count=5, $simple=TRUE) { $url = "http://twitter.com/statuses/user_timeline.json?screen_name={$screenname}&count={$count}&include_rts=1"; if ($http_response_header[0] != 'HTTP/1.0 200 OK'): return FALSE; endif; if ($simple == TRUE): foreach ($data as $tweet): $o = new stdClass; $o->id = $tweet->id_str; $o->url = "https://twitter.com/#!/{$screenname}/status/{$tweet->id_str}"; $out[] = $o; endforeach; $data = $out; endif; return $data; } $tweets = myTweets('sverrimo', 2);