【发布时间】:2017-07-17 22:18:02
【问题描述】:
我通过 CodeBird PHP 使用 twitter API 在网站上使用 Ajax 显示推文。我在第一次通话后无法防止重复,因为max_id 在包含 max_id 之后显示推文。
对我来说,他们为什么要这样做似乎很愚蠢,但我似乎也找不到其他人问同样的问题。我认为这将是很多人遇到的事情。这让我觉得我做的不对。
// Prepare Args
$tw_args = array(
'count' => 5,
'trim_user' => true
);
// If we havea last id, set it
if (isset($last_id)) {
$tw_args['max_id'] = $last_id;
}
// new tweet arr
$tweets = array();
// get raw tweets
$raw_tweets = (array) $cb->statuses_userTimeline($tw_args);
// loop through tweets
for ($i = 0; $i < count($raw_tweets); $i++) {
// Add just the ID and text to our new tweets array
$tmp = array(
'id' => $raw_tweets[$i]->id_str,
'text' => $raw_tweets[$i]->text
);
array_push($tweets, $tmp);
}
// return tweets array
return $tweets;
如何防止 twitter API 返回与 max_id 具有相同 id 的推文?
【问题讨论】: