【问题标题】:Reply a Tweet Only One Time只回复一次推文
【发布时间】: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 次。之后,即使我运行这个脚本,我也不希望它回复。

【问题讨论】:

    标签: php twitter


    【解决方案1】:

    您有多种方法来做到这一点:

    1. 使用数据库存储您已回复的推文的ID,并 忽略ID已经在数据库中的那些。
    2. 如果您的脚本运行 每 10 分钟自动,仅回复推文中的提及 在最后 10 分钟内发送。
    3. Look if you have already replied to the tweet.

    【讨论】:

    • 无法处理最后 2 个,但我确实通过使用数据库来完成。
    猜你喜欢
    • 2013-09-05
    • 1970-01-01
    • 2014-03-29
    • 2018-07-04
    • 2020-09-16
    • 2011-10-29
    • 1970-01-01
    • 2018-10-20
    • 2015-01-16
    相关资源
    最近更新 更多