Making a Twitter bot
Published Updated . Tags: English, Programming, APIs, Bots.
Update 17.3.2023: The post is out of date, because of Twitter's changed API policies.
I wanted to make a bot that would tweet energy saving tips. The idea was for it to be a part of Finland's national campaign aimed at citizens to reduce energy consumption for the coming winter.
Rough steps of what I did:
- Create a gmail account for the bot.
- Make a Twitter account for the bot.
- Apply for Twitter's developer account.
- Go through hoops of getting rights to read and write statuses, and API keys.
- Make a prototype:
- Make a Google Sheets document that works as a tweet database.
- Write Python script that fetches and posts statuses (manually).
- Get Google Sheets API, so your script can access the sheet.
- Move the Python script to Google Cloud.
- Automate the Python script with Google Scheduler.
- Get the bot running! Check out @energiarobotti.
By the way, I pretty much followed Aaron Jack's Twitter bot building video. It's a bit outdated, but it helps a lot. The sad thing is that he didn't show how to get the developer account for Twitter working. It's the most complicated part of the whole project.
Make it open source
Note that "open source" in this case means making the Sheet (content in Finnish) and the code available (without showing the API keys!). Contributing to the Sheet or code is not possible at the moment.
It is especially important to state your sources when giving advice that impacts people's wellbeing. It also drives you to make better.