How to set up a Twitter dev account, register Twitter app and generate Twitter API tokens
This guide takes you through setting up a new Twitter account all the way through to generated Twitter auth tokens (aka API tokens or credentials). These tokens must be used on every request, such as fetch or create Twitter content.
- Register a Twitter account.
- Apply for a Twitter developer account.
- Create a Twitter app.
- Create Twitter API tokens.
See detailed steps below.
- Register a new Twitter account.
- Login to your account.
Warnings:
- Create a new account. Avoid using your existing personal account for developing work in case your personal account gets blocked, even if you have been using it responsibly. I have been very cautious using a Twitter bot script to post at most once daily to a Twitter account and not targeting users or using bad content. Yet still, I have had my bot stop working a few times. Each time, I had to go to Twitter and login to the count and complete a "I'm not a robot" catcha challenge._
- If you are creating a bot account that creates tweets, you must include a notice in you bio that your profile is a who and supply the handle of your personal account. If you fail to do this, you account could get restricted.
Note - you will have include a written a motivation on how you will use the account and you will have to be with Twitter's usage restrictions. This application take a few days and even a few emails back and forth to Twitter, if you are not approved immediately.
- Go to Apply for access page in Twitter dev docs.
- Click the Apply button
- You'll be guided through the application process.
- Go to Apps page.
- Create an application. You select permissions, such as read-only or read and write access.
You could have multiple apps but you only need one.
- For your Twitter app, generate tokens.
- Copy the set of four tokens.
CONSUMER_KEY
CONSUMER_SECRET
ACCESS_KEY
ACCESS_SECRET
- Add them to your application as configured values.
- Starting fetching or creating tweets using your application.
Keep these secret!
Do not paste these into your script or even into a config file, if there is a risk of the values getting added to version control. Rather read from environment variables or a config file that is listed in .gitignore
.
Otherwise someone could do malicious things with your token. By abusing rate limits to search for tweets using your account, or even post tweets on your behalf.
- How to apply for a Twitter Developer account blog post
- Getting Started guide for using the Twitter API.
- Apps list page for your Twitter account.
- My notes on my Python Twitter Guide.