2
votes

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

1

1 Answers

2
votes

With the twitter API you can only get up to 200 posts per page. You would have to add a &page=x to get the tweets from timeline (limit of 3200 posts)

API documentation: https://dev.twitter.com/docs/api/1/get/statuses/user_timeline

$getfield = '?screen_name='.$sc_name.'&exclude_replies=true&include_rts=true&contributor_details=false&page=1';

use page=2 for next page with 200 more tweets :

$getfield = '?screen_name='.$sc_name.'&exclude_replies=true&include_rts=true&contributor_details=false&page=2';

you can also use for loop to get all the tweet from the timeline. You would be able to loop 16 times only hence you get could 3200 tweets (Maximum).

Hope this help.