Skip to content

Instantly share code, notes, and snippets.

@MichaelCurrin
Last active December 24, 2022 23:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save MichaelCurrin/da559dcda9f1a0a202b74f2127be5bf9 to your computer and use it in GitHub Desktop.
Save MichaelCurrin/da559dcda9f1a0a202b74f2127be5bf9 to your computer and use it in GitHub Desktop.
Twitter API tokens for a new account

Twitter API tokens

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.

Overview

  1. Register a Twitter account.
  2. Apply for a Twitter developer account.
  3. Create a Twitter app.
  4. Create Twitter API tokens.

Steps

See detailed steps below.

1. Get a standard Twitter account

  1. Register a new Twitter account.
  2. 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.

2. Get a Twitter developer account

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.

  1. Go to Apply for access page in Twitter dev docs.
  2. Click the Apply button
  3. You'll be guided through the application process.

3. Create a Twitter application

  1. Go to Apps page.
  2. 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.

4. Generate tokens

  1. For your Twitter app, generate tokens.
  2. Copy the set of four tokens.
    • CONSUMER_KEY
    • CONSUMER_SECRET
    • ACCESS_KEY
    • ACCESS_SECRET
  3. Add them to your application as configured values.
  4. 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.

Resources

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment