The twitter search API for "/search/tweets" is ignoring the max_id field. I think its because the OAuth.php library sorts the CGI params according to RFC 9.1.1, causing the max_id field to be listed before the OAuth tokens and the q parameter, and so you dont process the max_id field. If I edit the code to put the max_id at the end of the CGI params, it sometimes works and sometimes gives me an authentication error, so I cannot reliably use that as a work around either.
Here is the PHP code:
-
function search($query, $max_id)
-
{ -
$toa = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
-
-
// echo "Searching with MAX ID " . $max_id . "\n"; -
if ($max_id != null) {
-
return $toa->get('/search/tweets', array('q' => $query, 'count' => 100, 'max_id' => $max_id));
-
} else {
-
return $toa->get('/search/tweets', array('count' => 100, 'q' => $query));
-
} -
} -
-
do {
-
$results = search($argv[1], $max_id);
-
-
if (isset($results->errors)) {
-
if (!strcmp($results->errors[0]->message, "Rate limit exceeded")) {
-
echo "Pausing...\n";
-
sleep(300);
-
$results = search($argv[1], $max_id);
-
continue;
-
} else {
-
var_dump($results);
-
exit;
-
} -
} -
-
if ($verbose) {
-
var_dump($results);
-
} -
-
$count = 0;
-
foreach ($results->statuses as $result) {
-
echo str_replace("", " ", $result->id_str) . "";
-
echo str_replace("", " ", $result->created_at) . "";
-
echo str_replace("", " ", $result->user->location) . "";
-
echo str_replace("", " ", $result->user->followers_count) . "";
-
echo str_replace("*", " ", $result->text) . "\n";
-
$count++;
-
} -
-
if ($count == 0) {
-
echo "done\n";
-
exit;
-
} -
-
sleep(10);
-
-
$max_id = $results->search_metadata->max_id_str;
-
-
$pages++;
-
} while ($pages < $MAX);

