如何显示多个用户一小时前发布的推文(PHP 实现)

How to display tweets posted an hour ago from multiple users (PHP implementation)

长话短说 .. 我正在使用 Twitter API 检索推文并对其进行情感分析。现在我想获取有关一小时前发布的关键字的推文。如何用 PHP 实现这个?当前版本如下所示:

$contents = $connection->get("https://api.twitter.com/1.1/search/tweets.json?q=".$keyw."&locate=en&rpp=100");

我想如果幸运的话,最简单的解决方案可能是添加另一个搜索查询,例如 tweets.json?q=".$keyw."&locate=en&rpp=100&time=3600" 但不确定。在其他地方没有找到任何说明。

所以数据被检索为 json 并且如果使用 print_r($contents); 它将生成我认为的 PHP 数组。然后就是

[created_at] => Mon Nov 30 17:41:31 +0000 2009

也许我可以利用这个?谢谢你的帮忙。 :)

这是使用 DateTime 和 DateInterval 过滤的建议逻辑:

$tweets_recieved = array (/* the tweets you recieved */);
function callback ($tweet)
{
    $curr_date = new DateTime();

    if ($tweet['created_at']->add(new DateInterval("PT1H")) < $curr_date)
        unset($tweet);
}
// Res contains the tweets from less than an hour ago
$res = array_map('callback', $tweets_recieved);