Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[PHP] Twitter Search API の使い方
<?php
$search_word = 'http://example.com/';
$page_per_posts = 100;
$twitter_search_api = sprintf(
'http://search.twitter.com/search.json?q=%s&rpp=%d',
urlencode($search_word),
$page_per_posts
);
$results = array();
if ( $response = file_get_contents($twitter_search_api) ) {
$json = json_decode($response);
$list = (array)(isset($json->results) ? $json->results : array());
foreach ( $list as $item ){
$results[$item->id_str] = array(
'author' => $item->from_user_name ,
'author_id' => $item->from_user_id_str ,
'profile_url' => $item->profile_image_url ,
'tweet_url' => sprintf('https://twitter.com/%s/status/%s', $item->from_user, $item->id_str) ,
'datetime' => (int) strtotime($item->created_at) ,
'content' => $item->text ,
'geo' => $item->geo ,
'language' => $item->iso_language_code ,
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.