Skip to content

Instantly share code, notes, and snippets.

@wokamoto
Last active December 12, 2015 01:08
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 wokamoto/4689209 to your computer and use it in GitHub Desktop.
Save wokamoto/4689209 to your computer and use it in GitHub Desktop.
[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