Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/php
- <?php
- if(!$argv[1]) { die("DIAF\n"); }
- //https://dev.twitter.com/docs/working-with-timelines
- function min_by_key($arr, $key){
- $min = array();
- foreach ($arr as $val) {
- if (!isset($val[$key]) and is_array($val)) {
- $min2 = min_by_key($val, $key);
- $min[$min2] = 1;
- } elseif (!isset($val[$key]) and !is_array($val)) {
- return false;
- } elseif (isset($val[$key])) {
- $min[$val[$key]] = 1;
- }
- }
- return min( array_keys($min) );
- }
- $username = $argv[1];
- $maxid = "";
- while(true)
- {
- $url = "http://api.twitter.com/1/statuses/user_timeline.json?include_entities=true&include_rts=true&screen_name=".$username."&count=200";
- if(strlen($maxid) > 0)
- {$url .= "&max_id=".$maxid;}
- $data = file_get_contents($url);
- $result = json_decode($data, true);
- if(count($result) == 1)
- {
- break;
- }
- if(count($result) > 0)
- {
- $maxid = number_format(min_by_key($result,'id_str') - 2, 0, '.', '');
- foreach ($result as $data)
- {
- echo $data['created_at'] ." ". $data['id_str'] ." ". $data['text'] . "\n";
- }
- }
- else
- {
- break;
- }
- }
- ?>
Add Comment
Please, Sign In to add comment