Select a user profile that is most likely to be associated with the bot. This can be your own personal account, or you can create a new Twitter account altogether.
Keep in mind, if you create a new Twitter account solely for the bot, your personal information will still need to be verified – like phone number and email address.
Request developer access on behalf of your organization or for personal use.
Organization – Select this option if your bot will be tied to an organization. You’ll need to enter some details about your organization such as its website URL, primary country of operation, where most of its customers are located, and industries you serve.
Personal use – Select this option if your bot is simply a side project.
Use case details
Twitter needs to understand why you’re creating a developer account in the first place.
Whether it’s understanding your target audience, detecting trends, or simply curating tweets, you’ll need to specify your intent to get approved.
After specifying a use case, you’ll be required to answer four additional questions about using Twitter APIs. Be detailed and truthful in this explanation, as Twitter wants to ensure its platform isn’t being leveraged for spam.
Lastly, Twitter would like to know if the content from this app will be available to a government entity. Failing to disclose this information could get your application rejected.
Terms of service
I get it. Reading through any terms of service can be a lengthy process. So, I’ll break down what you’re agreeing to by applying for a developer account.
Reverse engineering – Don’t attempt to unveil the source code of any Twitter API. Don’t modify or disrupt the features and functionality of any Twitter API. Don’t sell, rent, lease, or license data to third-parties.
Rate limits – In short, don’t spam users with your bot.
Geographic data – This data can only be used to identify the tagged location of Twitter content like tweets, retweets, direct messages, and more.
Use of Twitter marks – In short, don’t use the Twitter logo for this account.
After scrolling through the full terms of service and agreeing to them, the final step requires you to verify your identity via email address.
2. Create a Twitter app
Now that you’ve verified your developer account, it’s time to create your first Twitter app. This app will be used to power your bot.
On the developer homepage, click on Create an App, which should bring you to the page below:
There are a few details about your app you’ll need to specify before acquiring API keys and access tokens.
Pretty self-explanatory. What is the name of this project?
Whichever name you go with will appear as the source of a tweet. Think of a username instead of a twitter handle.
Tell users what your app will consist of. This should support your app’s name.
For example, we’re creating a bot that will retweet content coming out of our Learn Hub, so I notify users accordingly.
Any tweet coming from your bot will need to be attributed to a source. This source should be your website URL.
The last required field is notifying Twitter employees of your app’s purpose. While this seems redundant, Twitter wants to ensure your app is aligned with its terms and conditions.
3. Setup a development environment
From Python to Node.js, Twitter bots can be programmed, tested, and deployed in virtually any development environment.
However, for the sake of simplicity, we’re going to utilize a Google script for Twitter bots written by world-renowned CS engineer and tech writer Amit Agarwal of labnol.
4. Link your Twitter app and dev environment
Your Twitter app and development environment need to be able to communicate with each other in order for your bot to work.
Begin locating your Twitter app’s API keys and access tokens. These can be found next to App details. You may need to generate an access token and an access token secret.
As a heads up, there’s a reason why I’ve greyed out my API keys and access tokens. Anyone with these keys will be able to access your account, so I advise against publicly posting them.
Also, be sure to check out your app’s permissions. It’ll be set to ‘read and write’ by default, which essentially means your app can perform basic Twitter functions.
However, if you’d like your app to be capable of direct messaging users, click on ‘read, write, and direct messages.’
Finally, head to Agarwal's script and enter the four keys in the respective fields to link your Twitter app and development environment.
5. Program the bot
Now comes the fun part – programming your Twitter bot.
There are a few aspects of this script you should familiarize yourself with. I’ll break down each one:
Twitter Search – Your commands will be entered here. This is the most important part of programming your bot since Twitter needs to know what to search for.
Action – The next most important part of programming your bot is choosing an action it will take. For example, will your bot retweet anything with a certain hashtag? Will it send a ‘thank you’ direct message to every new follower? You need to specify its action before deploying. For a full list of actions, check out Agarwal’s documentation.
Text – An action can be done without context, but where’s the fun in that? It’s advisable to add text next to an action to give those who engage with your bot a more personalized experience.
Start and End Time – This neat feature allows you to program a start and end time for your bot to function. This could be useful when notifying followers that the team is out-of-office and will get back to them first thing in the morning.
Now, let’s go back to actions since there are so many of them.
In the example below, I program the bot to send a public reply to every tweet mentioning the phrase “internet of things.” The reply’s text will consist of “We love IoT! Check out our guide here: [ insert link ]”
This next bot will be programmed to send a private direct message to all new followers. The search field should contain your Twitter handle, in this case, that’s @G2Crowd. The direct message’s text will consist of “Thanks for the follow! Check out our website and leave a software review.”
The final bot that I’ll actually implement will retweet content with our custom hashtag #G2LearnContent. I set the minimum favorite count to “1,” which essentially means all tweets with this hashtag will be quoted by the bot as long as it has one like or favorite. You can set this amount to as high as you’d like.
The quoted text in the retweet will be “Check out the latest content coming out of the @G2dCrowd Learn Hub!”
I enter the API keys and access token credentials, click Save, and voila, the bot has been deployed. Now it’s time to test it.
6. Test the bot
If all goes well, your bot should be completing its action, but it doesn’t hurt to run some tests.
Click on Check near the bottom of the script to see if any activity has been logged. For example, I’ll see the number of retweets on Twitter with my custom hashtag.
As you can see, the bot has completed its desired action.
If no action is logged, this doesn’t necessarily mean your bot is broken. However, you might want to revisit the bot after a few days to ensure your API keys and access tokens are correct.
It’s also worth noting that Twitter has fairly strict guidelines regarding automation and bots. As mentioned before, don’t program your bot to spam users or retweet sensitive content. This could cause your bot to shut down, and may even lead to your Twitter app getting revoked.
Twitter bot solutions
Programming a Twitter bot is definitely a fun side project, but there are greater uses outside this for business users.
For example, you can build out a robust Twitter bot as part of your fleet of social media marketing solutions. Your bot can provide valuable customer service when a human isn’t active. It can even curate a list of Twitter accounts that align perfectly with your business – increasing your brand awareness. For smarter bots with multi-purposes, however, it's worth looking into bot platforms software.
However you decide to program your Twitter bot, be sure to follow the above steps closely and experiment with different actions.
Twitter bots aren’t the only bots taking social media by storm. Check out our complete guide on Facebook chatbots and the ways businesses are leveraging them to automate marketing, customer service, and even sales.
Devin is a former senior content specialist at G2. Prior to G2, he helped scale early-stage startups out of Chicago's booming tech scene. Outside of work, he enjoys watching his beloved Cubs, playing baseball, and gaming. (he/him/his)