Step 1 - Setting up to use the Twitter API
You need to sign up for access to the Twitter API. You will also create a project in the developer portal and an App containing the credentials required to use the Twitter API. Additionally, you will need to have OAuth 2.0 turned on in your App’s authentication settings. The developer playground is a great place to start using the Twitter API.
Step 2 - Set up a Twitter account for your bot
You will want to create a new Twitter account for your bot handle. Afterward, you will want to set up the profile for your bot, including adding a profile picture and banner image and setting up a label to indicate your bot is automated.
Step 3 - Remix the Glitch example
You can remix our code sample on Glitch. After, you will want to update the
.env file inside of Glitch to include the following fields:
You can obtain your client ID and client secret from the developer portal. The Glitch project name will be generated when you remix the project. You will also need to add your redirect URI in your App’s authentication settings in the developer portal.
To download all the requirements you need, you can run the following command in the terminal inside of your Glitch project.
Step 4 - Tweet your bot’s first Tweet
Now that you’ve set everything up, you can start Tweeting from your bot’s handle. To do so, you can visit the site you’ve created and click the green button that says “Let’s Begin.”
This should look like this:
Step 5 - Make it your own
To customize this bot, you may want to change it, so it doesn’t just Tweet noun/verb pairings. You can update this function to call different APIs. To find inspiration, you can look at the APIs available in Postman or ProgrammableWeb’s API directory.
Another way you can personalize your bot is by adjusting the timing of the bot. This bot currently Tweets hourly, but you can change the variable to run at a different time interval. Check out the Flask APScheduler documentation for more information.
This is the line of code you will want to update to adjust the timing of your bot: