hikari_no_yume / twitterbot
PHP 7.0 的 Twitter Bot 框架
v1.0
2017-05-03 16:14 UTC
Requires
- php: >=7.0
- j7mbo/twitter-api-php: ^1.0
This package is not auto-updated.
Last update: 2024-09-15 02:37:46 UTC
README
简单的 PHP 7.0 Twitter Bot 框架。将 "hikari_no_yume/twitterbot"
添加到您的 Composer 依赖中。
使用方法
创建一个实现了 hikari_no_yume\TwitterBot\TweetDeviser
的类。这只需要一个返回 string
的 devise
方法。例如
class MyTwitterBot implements TweetDeviser { public function devise(): string { return "Hello, world!"; } }
这是您机器人的核心。每当要发布一条推文时,都会调用 devise()
,并使用返回的字符串发布推文。
然后您只需要编写一个简单的脚本,创建一个 hikari_no_yume\TwitterBot\Tweeter
对象,将其 TweetDeviser
传递给它,设置适当的配置参数,并启动它
<?php declare(strict_types=1); use hikari_no_yume\TwitterBot\Tweeter; require_once __DIR__ . '/vendor/autoload.php'; $tweeter = new Tweeter(new MyTwitterBot); // Loads Twitter oauth_access_token, oauth_access_token_secret, consumer_key and consumer_key from a JSON file // You can also get these from somewhere else and use $tweeter->setTwitterKeys($object) $tweeter->loadTwitterKeysFromJSONFile("settings.json"); // Optional. Sets the interval between tweets, in minutes. The default is 30. $tweeter->setTweetInterval(30); // Optional. Sets how long to wait before retrying devising a tweet (if it threw a Throwable), in seconds. The default is 60. $tweeter->setDeviseRetryInterval(60); // Optional. Sets how long to wait before retrying sending a tweet (if it failed), in seconds. The default is 60. $tweeter->setTweetRetryInterval(60); // Runs the bot forever. $tweeter->run();
恭喜,您现在有一个 Twitter 机器人了!
许可
Copyright © 2017 Andrea Faulds.
PHP7-Twitter-Bot is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
PHP7-Twitter-Bot is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with PHP7-Twitter-Bot. If not, see <https://gnu.ac.cn/licenses/>.