This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 , | |
); | |
} | |
} |
$search_word は検索したい文字列、$page_per_posts は一度に取得するツイート数、$results に検索結果が入るよ。
コメントを残す