Php TwitterAPI-每次加载X个帖子

Php TwitterAPI-每次加载X个帖子,php,twitter,Php,Twitter,我有三篇推特帖子如下: -> Twitter with message 3 -> Twitter with message 2 -> Twitter with message 1 带有消息3的Twitter是我的时间线中最近的一个 我试图按降序(从最新到最旧)一次检索一篇文章。我下面的twitterapi文档是 根据API,我正在尝试实现一些代码逻辑,因此我有一个如下函数: function getPosts($lastTwitterId = null) { //

我有三篇推特帖子如下:

-> Twitter with message 3 
-> Twitter with message 2 
-> Twitter with message 1
带有消息3的Twitter是我的时间线中最近的一个

我试图按降序(从最新到最旧)一次检索一篇文章。我下面的twitterapi文档是

根据API,我正在尝试实现一些代码逻辑,因此我有一个如下函数:

function getPosts($lastTwitterId = null)
{
    // I always retrieve 1 at a time (for testing purposes)
    $data = ['user_id' => 'my user id', 'count' => 1];

    // Get last twitter Id retrieved
    if ($lastTwitterId)
        $data['max_id'] = $lastTwitterId;

    return $twitter->get('statuses/user_timeline', $data);
}
使用此代码,我将获得以下行为:

-> grabs posts
    -> Twitter with message 3 -> OK 
-> grabs next posts 
    -> Twitter with message 3 -> NOT OK DUPLICATED (should get -> Twitter with message 2)
-> grabs next posts  
    -> Twitter with message 3 -> NOT OK DUPLICATED (should get -> Twitter with message 1)

我已经检查过,
$lastTwitterId
变量在第一次调用后正确获取值。

已解决

解决办法就在这篇文章里。我唯一需要改变的是:

$data['max_id'] = $lastTwitterId;
为此:

$data['max_id'] = $lastTwitterId - 1;