【发布时间】:2018-06-12 13:43:24
【问题描述】:
我正在使用 Twitter API 和 PHP 来回复特定的推文。
例如。如果其他用户像“@Diga 回复我!”这样提到我。我正在回复他们。否则,我只是放弃提及。
这是一个基本的 if 语句,我可以处理。问题是,当另一个用户提到我并且我再次运行脚本时,脚本会回复他们两个,因为已经有另一个人提到了。
$statues = $connection->get("statuses/mentions_timeline");
if(count($statues)>0)
{
$message= strtolower($statues[0]->text);
$message= trim(str_replace("@diga","",$message));
if($message== "reply me!")
{
$user_name = "@".trim($statues[0]->user->screen_name);
$tweetID = $statues[0]->id_str;
$statues = $connection->post("statuses/update", ["status" => $user_name." I can reply you!", "in_reply_to_status_id" => $tweetID]);
}
}
else
{
echo "no mention.";
}
在此代码中,如果有任何提及,脚本将开始检查消息。实际上,由于测试,我只检查一个提及(0)。但是,我只想回复这条推文 1 次。之后,即使我运行这个脚本,我也不希望它回复。
【问题讨论】: