1

试图从用户返回过去 24 小时内的所有推文,但不知道该怎么做,这是我目前拥有的代码,只是为了获取最后 5 条推文,不知道下一步该怎么做.. .

谢谢马特。

<?php
$username = "MelbournePollen";
$count = 5;
$tweet=json_decode(file_get_contents("http://api.twitter.com/1/statuses/user_timeline/".$username.".json?count=".$count."" ));

for ($i=1; $i <= $count; $i++){
    //Assign feed to $feed
    $feed = $tweet[($i-1)]->text;
    echo date("M \- j",strtotime($tweet[($i-1)]->created_at)). " -- " .$feed. "</br>";
    }?>
4

1 回答 1

1

以下代码应基于您的逻辑引导您朝着正确的方向前进(我的代码未经测试):

<?php
    $username = "MelbournePollen";
    $count = 5;
    $tweet=json_decode(file_get_contents("http://api.twitter.com/1/statuses/user_timeline/".$username.".json?count=".$count."" ));

    $tweets = array();
    for ($i=1; $i <= $count; $i++){
        //Assign feed to $feed
        $feed = $tweet[($i-1)]->text;
        $time_between = time() - strtotime($tweet[($i-1)]->created_at);
        $twenty4hours = 60 * 60 * 24;
        if($time_between <= $twenty4hours)
        {
            $tweets[] = $tweet;
        }
    } 
    //Use $tweets array as needed
?>
于 2012-11-29T15:50:09.093 回答