尝试在过去24小时内从用户返回所有推文,但不知道该怎么做,这是我到目前为止的代码,这只是为了得到最后5条推文,不知道如何做下一个步骤...
THX 太
<?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>";
}?>
答案 0 :(得分: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
?>