i am using twitter user_timeline api to get all tweets of a user .
it returns 200 in single request but problem is that i want to get all tweets if tweets are like 400 or 500
below is my code that give 200 tweets in output :
require_once('TwitterAPIExchange.php');
$settings = array(
'oauth_access_token' => "",
'oauth_access_token_secret' => "",
'consumer_key' => "",
'consumer_secret' => ""
);
$requestMethod = 'GET';
$url1="https://api.twitter.com/1.1/statuses/user_timeline.json";
$sc_name = 'DailyRapPics';
$count ='700';
$getfield = '?screen_name='.$sc_name.'&exclude_replies=true&include_rts=true&contributor_details=false';
$twitter = new TwitterAPIExchange($settings);
$tweets = $twitter->setGetfield($getfield)->buildOauth($url1, $requestMethod)->performRequest();
$tweetarray = json_decode($tweets);
$l = 0;
foreach($tweetarray as $mytweets){
$l++;
}
echo 'total values->>>>>>>>>'.$l;
when i see twitter there are field like since_id,max_id
how can i use it to get all tweet of user less than 3200 of twitter limit please help me
what could be value od max_id and since_id here please guide
Your question regards to how to paginate (since the request param "count" has a maximum of 200 results per query according to Twitter's user_timeline API), but it allows you to get the last 3200 tweets.
The right way to paginate it is with the ids of the tweets in an algorithm like this:
Initialise variables
$all_tweets = array();
$max_tweets_per_response = 200;
$last_tweet_id = 0;
$max_tweets_you_want_to_obtain = 666;
Decode response received from Twitter and merge it with the variable that will contain all 3200 results.
$tweetarray = json_decode($tweets);
$all_tweets = array_merge($all_tweets, $tweetarray);
$last_tweet_id = the ID of the LAST tweet you received, that right now will be the one in the variable $tweet
Iterate from step 2 onwards until
count($tweetarray) < $max_tweets_per_response
or
count($all_tweets) >= $max_tweets_you_want_to_obtain
Do whatever you need with all your tweets, that will now be contained in variable $all_tweets
echo 'total values->>>>>>>>>'.count($all_tweets);