Create a Twitter bot

Prerequisites: a Twitter account, moderate command line and Google Cloud experience.

Time to complete: a couple of hours.

Alternatively you might consider GitLab hosting.

Developer account

Apply for a Twitter dev account, create an app and make a note of the two API keys. Keep them to yourself.

Google Cloud hosting

Create the smallest (and cheapest) Linux instance on Google Cloud.

Installation

Connect to your instance and install the essentials.

sudo apt update && sudo apt install rubygems --yes && sudo gem install twurl

Authentication

Authenticate your instance with the two keys you saved earlier. There's quite a cool PIN exchange with Twitter too.

twurl authorize --consumer-key xxxxxxxx --consumer-secret xxxxxxxx

This will write your authentication details into ~/.twurl which you can copy to another machine and use without reauthenticating.

Schedule

Connect to your instance and edit your cron tab to make your job run every minute (note the explicit path to twurl).

crontab -e

See cron tab guru for the syntax. See what cron is up to.

tail -f /var/log/syslog

References

results matching ""

    No results matching ""