Twitter bot using the AMP asynchronous framework for PHP.
Although the version of AMPHP in this example does not require PHP 7.x, the Twitter client does require it. It was way too much work to build a 5.6 Twitter client for streams. So I went with requiring PHP 7.x.
The intl extension is required as the Twitter API supports multi-byte characters.
If you are not familiar with Composer, head to https://getcomposer.org/doc/00-intro.md and install Composer. Once installed, spend a few moments reflecting on all you could have accomplished had you done this sooner.
- Clone the repo
git clone https://github.com/aenglander/amp-twitter-bot.git
- Change to directory
cd amp-twitter-bot
- Composer install
./composer.phar install
- Create a Twitter account. You will probably want an separate account for your bot.
- Create a new app at Twitter Dev logged in as your bot account: https://apps.twitter.com/app/new
Copy the ./keys.php.example file to
keys.php
and update the values as instructed.
The User Timeline example utilizes the Twitter REST API to make a single request.
Run php timeline.php
to run the example. It
will print out a pretty formatted JSON string of the
result.
The Stream example will connect to the Twitter User Stream API and print out every Twitter update matching the filter criteria.
Run php stream.php
to run the example. It will
print out the twitter username and update text. You can press
<CTRL><c>
at any point to end the stream.
The Twitter Bot will connect to the Twitter User Stream API
and and respond to every update matching the filter criteria
that was not from itself. You can press
<CTRL><c>
at any point to end the stream.
The Twitter Stream Portal will start a website that serves up a Twitter feed to multiple browsers through the magic of Web Sockets.
Run vendor/bin/aerys -c config.php -d
to start the Aerys
web server and start broadcasting the stream. You can press
<CTRL><c>
at any point to end the stream.
Once the server is started, simply access the web server on port 8080 on any IP for your computer. Most will work for localhost at http://localhost:8080/.