【问题标题】:Twitter API - load X posts each timeTwitter API - 每次加载 X 个帖子
【发布时间】:2020-05-19 16:39:07
【问题描述】:

我有以下三个 Twitter 帖子:

-> Twitter with message 3 
-> Twitter with message 2 
-> Twitter with message 1

Twitter with message 3 是我时间线中最新的。

我正在尝试一次检索 1 个帖子,按降序排列(从最新到最旧)。我关注的 Twitter API 文档是 https://developer.twitter.com/en/docs/tweets/timelines/api-reference/get-statuses-user_timeline

根据 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 变量在第一次调用后正确获取了值。

【问题讨论】:

    标签: php twitter


    【解决方案1】:

    已解决

    解决方案在这篇帖子using since_id and max_id in Twitter API。我唯一需要改变的是:

    $data['max_id'] = $lastTwitterId;
    

    进入这个:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-12-07
      • 1970-01-01
      • 1970-01-01
      • 2017-08-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多