Permalink
Browse files

Fixed undercounting of tweets due to pagination

  • Loading branch information...
1 parent ad79d6e commit 6abdcb56774e7266d298f5341e6517e95bdd8024 Dan Copeland committed Jun 7, 2011
Showing with 15 additions and 1 deletion.
  1. +15 −1 calculate.php
View
@@ -37,7 +37,21 @@ public static function twitter($url, $modifier = 1)
return self::prepare_return(0, $modifier);
}
- return self::prepare_return(count($item_data->results), $modifier);
+ $total_count = 0;
+ while (isset($item_data->next_page))
+ {
+ $total_count += count($item_data->results);
+ $json = @file_get_contents('http://search.twitter.com/search.json' . $item_data->next_page);
+ if (empty($json))
+ {
+ $item_data = (object) array('results' => array());
+ break;
+ }
+ $item_data = json_decode($json);
+ }
+ $total_count += count($item_data->results);
+
+ return self::prepare_return($total_count, $modifier);
}
public static function facebook($url, $modifier = 1)

0 comments on commit 6abdcb5

Please sign in to comment.