Skip to content

Instantly share code, notes, and snippets.

@amitavroy
Created June 10, 2013 12:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amitavroy/5748254 to your computer and use it in GitHub Desktop.
Save amitavroy/5748254 to your computer and use it in GitHub Desktop.
Get all tweets of a specific hashtag
function getTweets($hash_tag) {
$url = 'http://search.twitter.com/search.atom?q='.urlencode($hash_tag) ;
echo "<p>Connecting to <strong>$url</strong> ...</p>";
$ch = curl_init($url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, TRUE);
$xml = curl_exec ($ch);
curl_close ($ch);
//If you want to see the response from Twitter, uncomment this next part out:
//echo "<p>Response:</p>";
//echo "<pre>".htmlspecialchars($xml)."</pre>";
$affected = 0;
$twelement = new SimpleXMLElement($xml);
foreach ($twelement->entry as $entry) {
$text = trim($entry->title);
$author = trim($entry->author->name);
$time = strtotime($entry->published);
$id = $entry->id;
echo "<p>Tweet from ".$author.": <strong>".$text."</strong> <em>Posted ".date('n/j/y g:i a',$time)."</em></p>";
}
return true ;
}
getTweets('#cats');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment