Twitter API Key – How to Generate Twitter Consumer Key and Access Token
In order to create a Twitter App, you always need Twitter API Keys (consisting of Twitter Consumer Key and Twitter Access Token). At first, I was including the information of how to generate twitter API keys along with a different article about creating a twitter bot.
However, I later realized that this information is worthy of its own article and thought that if I’m going to refer to these API Keys many times in my upcoming articles then I should better let my readers know what actually Twitter Consumer Keys and Access Tokens are and how you can generate them.
But first, let me clarify very briefly the differences between Twitter Consumer Key, Consumer Key Secret and Twitter Access Token and Access Token Secret.
Twitter Consumer Key and Consumer Key Secret
Every application needs an identification. Just like a username for any website. Similarly, the consumer key acts like a username for your app. Any website, whose API you’re going to use (in this case, Twitter) needs this identification to provide you access. So plainly put, Twitter Consumer Key is akin to what usernames are to any membership website.
Consumer Key Secret
This is just like a password for your app to access the API. This secret key is used to authenticate with the authentication server. In our case, Twitter. Needless to say that you need to protect your consumer key secret just like you protect your normal password.
Twitter Access Token and Access Token Secret
Once you get authenticated using your consumer key and secret, you are provided with the access token. Access token contains information about the privileges and the rights particular app has.
Access Token Secret
Again, just like the consumer key secret, access token secret is sent with the access token and acts like a password to your access token.
How To Generate Twitter Consumer Key and Consumer Secret Codes
To generate your own Twitter Consumer Key, Consumer Secret codes, follow the below steps:
- Log in to apps.twitter.com. The same Twitter credentials will work here.
- Click Create New App button.
- Enter the name of your application in the Name field. This should be unique.
- Enter description of your app in the Description field.
- Enter the URL of your website. This is the website where your app will reside so that your users can download or gain more information about your app. In case you don’t have a website then enter a placeholder for time being. But remember, in the long run, in case you want your app to be publicized, you may need to enter your website’s URL.
- Enter the Callback URL. This is the URL users are redirected to when successfully authenticated. Since this is an optional field, you can also leave it blank.
- Accept Twitter’s terms and conditions
- Click Create your twitter application.
- On the very next screen that shows up, go to Keys and Access Tokens tab to get your Consumer API Key and Consumer Secret. Remember, your Consumer Secret is a “Secret Code” and should not be shared with anyone.
How to Generate Twitter Access Token and Access Token Secret
Once you have your own Twitter Consumer API Key and Consumer Secret codes, let’s now see how you can generate Access Tokens and Access Tokens Secret.
While staying in the Keys and Access Tokens tab mentioned above, do the following:
- Right at the very bottom of the screen, in the Token Actions section, click the button, Create My Access Token.
- The screen will be refreshed and your access token is created now.
- To check your tokens, scroll below and you will see your tokens in Your Access Token section.
- Your Access Token Secret is your secret code and should not be shared with anyone. Do I need to emphasize any more?
So above is the way you can generate your consumer API keys for your apps to integrate with Twitter API. You may need to refer to this method not once but every time you create a new app to integrate and fetch Twitter data via Twitter API.
Do let me know in the comments section if this article was helpful or if I missed anything.