Php twiiter max_id和since_id

Php twiiter max_id和since_id,php,api,twitter,Php,Api,Twitter,我正在使用twitter user_timeline api获取用户的所有推文 它在一个请求中返回200条,但问题是,若tweets是400条或500条,我希望获得所有tweets 下面是我的代码,输出200条推文: require_once('TwitterAPIExchange.php'); $settings = array( 'oauth_access_token' => "", 'oauth_access_token_secret' => "",

我正在使用twitter user_timeline api获取用户的所有推文

它在一个请求中返回200条,但问题是,若tweets是400条或500条,我希望获得所有tweets

下面是我的代码,输出200条推文:

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;
当我看到twitter时,有一个字段类似于since_id,max_id

我如何使用它来获取twitter限制3200以下用户的所有推文请帮助我


根据,请求参数计数每个查询最多有200个结果,但它允许您获得最后3200条tweets,因此请引导您关于如何分页的问题

正确的分页方法是使用tweet的id,算法如下:

初始化变量

$all_tweets = array();
$max_tweets_per_response = 200;
$last_tweet_id = 0;
$max_tweets_you_want_to_obtain = 666;
$tweets=查询结果与您执行查询的方式相同,但也添加了参数: count=$max\u tweets\u per\u response&since\u id=$last\u tweet\u id 解码从Twitter收到的响应,并将其与包含所有3200个结果的变量合并

$tweetarray = json_decode($tweets);
$all_tweets = array_merge($all_tweets, $tweetarray);
$last_tweet_id=您收到的最后一条tweet的id,此时将是变量$tweet中的id

从步骤2开始迭代,直到

count($tweetarray) < $max_tweets_per_response
or
count($all_tweets) >= $max_tweets_you_want_to_obtain

您的问题涉及如何分页,因为根据,request param count每个查询最多有200个结果,但它允许您获取最后3200条推文

正确的分页方法是使用tweet的id,算法如下:

初始化变量

$all_tweets = array();
$max_tweets_per_response = 200;
$last_tweet_id = 0;
$max_tweets_you_want_to_obtain = 666;
$tweets=查询结果与您执行查询的方式相同,但也添加了参数: count=$max\u tweets\u per\u response&since\u id=$last\u tweet\u id 解码从Twitter收到的响应,并将其与包含所有3200个结果的变量合并

$tweetarray = json_decode($tweets);
$all_tweets = array_merge($all_tweets, $tweetarray);
$last_tweet_id=您收到的最后一条tweet的id,此时将是变量$tweet中的id

从步骤2开始迭代,直到

count($tweetarray) < $max_tweets_per_response
or
count($all_tweets) >= $max_tweets_you_want_to_obtain

请看,这可能没有直接关系,但只是为了帮助您,您需要使用max_id和since_id作为字符串或浮点数。您将省去很多麻烦。请看,这可能没有直接关系,但只是为了您的帮助,您需要使用max_id和since_id作为字符串或浮点数。你会省去很多头痛。