php - How do I the max limit (3200 tweets) using Twitter's API (1.1) -
i have been able it's in rather 'ugly' way.
one problem i'm facing refactoring need phone call 'max_id' need utilize placeholder until create first call. i've tried using 'null' , '' $max_id neither work. also, have feeling written without using manual 'for' loop.
so far code:
$i = 1; $content = $connection->get('statuses/user_timeline', array('screen_name' => 'username', 'count' => '200')); foreach ($content $item) { echo $i . " : " . $item->text; echo("<hr>"); $i++; } $lasttweet = end($content); $max_id = $lasttweet->id_str; ($l = 0; $l<15; $l++) { $content = $connection->get('statuses/user_timeline', array('screen_name' => 'username', 'count' => '200', 'max_id' => $max_id)); foreach ($content $item) { echo $i . " : " . $item->text; echo("<hr>"); $i++; } $lasttweet = end($content); $max_id = $lasttweet->id_str; }
any help appreciated.
i know it's not beautiful, within loop couldn't set test variable. sort of first time through instance or ruin point of refactoring?
$maxid = false; if(!$maxid) $content = $connection->get('statuses/user_timeline', array('screen_name' => 'username', 'count' => '200')); else { $content = $connection->get('statuses/user_timeline', array('screen_name' => 'username', 'count' => '200', 'max_id' => $max_id)); $maxid = true; }
instead of loop if you're careful away while loop() goes off count of items returned increment variable number of tweets returned on each pass. never accidentally allow while loop run forever, or can goodbye twitter api requests awhile.
$counttweets = 0; while($counttweets < 3200) { //code calls, gotta $counttweets += count($content); }
i utilize similar have, except merge next set of tweets total array work off big list of tweets. test count of total merged array instead of adding count variable.
php refactoring twitter
No comments:
Post a Comment