<?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 に検索結果が入るよ。
“[PHP] Twitter Search API の使い方” への1件のフィードバック