Pulling recent hashtags from twitter
- 9 October, 2011 -
- PHP, Twitter Dev -
- Tags : JSON, PHP, Twitter
- 0 Comments
This code pulls a json of a hashtag search from twitter. It runs some functions to add to a database. (functions not included.)
global $total, $hashtag;
$hashtag = '#somehashtag';
$total = 0;
function getTweets($hash_tag, $page) {
global $total, $hashtag;
$url = 'http://search.twitter.com/search.json?q='.urlencode($hash_tag).'&';
$url .= 'page='.$page;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$json = curl_exec($ch);
curl_close ($ch);
$json_decode = json_decode($json);
$json_output = json_decode($json,true);
for($c=0;$c<=count($json_decode->results);$c++){
if(isset($json_output['results'][$c]['id_str'])){
if(!tweet_exists($json_output['results'][$c]['id_str'])){
add_tweet($json_output['results'][$c]['id_str'],
$json_output['results'][$c]['from_user'],
$json_output['results'][$c]['created_at'],
$json_output['results'][$c]['profile_image_url'],
$json_output['results'][$c]['text']);
}
}
}
if($json_decode->next_page){
$temp = explode("&",$json_decode->next_page);
$p = explode("=",$temp[0]);
getTweets($hashtag,$p[1]);
}
}