簡體   English   中英

顯示過去24小時的推文

[英]display tweets for last 24 hours

試圖從用戶處返回過去24小時內的所有tweet,但不確定如何執行,這是我到目前為止的代碼,僅是獲取最后5條tweet,不知道如何執行下一步。 。

馬克斯

<?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>";
    }?>

以下代碼應在您的邏輯基礎上引導您朝正確的方向發展(我的代碼未經測試):

<?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
?>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM