Social Media

To collect data from Twitter, you need to have keys to the Twitter API. API documentation can be overtly technical and confusing to even experienced developers. Twitter's API is comparatively easy to navigate - once you know how.

This guide will walk through the process of accessing the keys required to authenticate your requests for data from Twitter. Ultimately, you want to finish this guide with four keys in hand; a API key, an API secret key, an Access token and an Access token secret. These are the codes that gain you access to collecting Twitter data using whichever method you prefer. To do this, you need to create a Twitter developers account and a Twitter app (it's not as complicated as it sounds).

"An API that isn't comprehensible isn't usable."

- James Gosling

After you have retrieved your keys, you are good to go! We've written this follow-up guide and notebook to help you collect tweets using the Twitter API. If you already have the keys, you should head straight over there.

Creating a Twitter Developers Account

To access the Twitter API, you need a Twitter account and a Twitter developers account. A developers account gives you a set of tools to start creating and managing projects that request data from Twitter.

In order to get a developers account you need to tell Twitter about yourself and your intentions for the account. Twitter will then review and approve your application. Give thoughtful and concise answers and they will normally get back to you pretty quickly. Sign up for a developers account here.

Creating a Twitter developers account.

How to Create a Developer Account with Twitter?

  1. Start here.
  2. Click 'Apply for developers account'.
  3. Select 'Hobbyist' or whichever category suits you best. We will use 'Hobbyist'.
  4. Select 'Exploring the API' and then 'Get Started'.
  5. Complete the text fields on the 'Basic info' form and select 'Next'.
  6. Inside the 'Intended use' form, Twitter requires some detailed information from you regarding how you intend to use their API. Take your time and fill in each text box thoroughly. When you are finished, click 'Next'.
  7. Inside the 'Review' form, review the information you've just provided.
  8. Inside the 'Terms' form, check over the terms of use and tick the checkbox.
  9. Select 'Submit Application'.
  10. Done ... Twitter will review your application and get back to you.

Once your developer's account has been approved you can create an app giving you access to the keys required to start making requests. Head over to the 'Developer Portal' to start creating an app.

Creating a Twitter Developer App

Twitter apps aren't necessarily apps in the way that we understand them. They are the entity that you use to request data from Twitter but they don't have to have a fancy UI or in fact any UI at all. In reality, they are just a way of telling Twitter where your request is coming from. It's important to remember that apps are not the same thing as projects.

You want to create an app, not a project. Make sure your developer account has been approved and then start creating an app.

Creating a Twitter developer app.

How to Create a Twitter App?

  1. Start here.
  2. Click 'Developer Portal' from the top menu.
  3. Select 'Overview' within the 'Projects & Apps' dropdown from the sidebar of your Twitter developer dashboard.
  4. Under 'Standalone Apps', click 'Create App'.
  5. Enter a name for your app.
  6. Select 'Complete'.
  7. Done ... Twitter will now present you with your API key and your API secret key. Make a note of these!

The Keys

Now that you have a developers account and have created an app using it, you should have access to all of the keys you need to start retrieving data from the Twitter API. If you didn't collect your API key and API secret key as you created the app, head over to your app's Keys and Tokens window to regenerate them.

It's important to remember that once you regenerate keys for an app, every instance of these keys will change. If you build projects using the old keys, you'll need to change everything over so that your requests are made using the new keys.

As well as the API key and the API secret key, you need to make a note of your Access token and Access token secret. You should see a way to regenerate these inside of your app's Keys and Tokens window. The same regeneration rules apply.

Accessing your Twitter app's API keys.

How to Find Twitter API Keys?

  1. Start from inside of your Twitter developer portal.
  2. Navigate to the app you just created using the left sidebar.
  3. Switch to the Keys and Tokens window inside of the app.
  4. Regenerate your API key and API secret key using the button under the Consumer Keys section.
  5. Make a note of these.
  6. Regenerate your Access token and Access token secret using the button under the Authentication Tokens section.
  7. Make a note of these.
  8. Done ... You are ready to start collecting data from Twitter

Now that you've got these keys, it is time to start putting them to use. We've written a guide on collecting tweets here and provided all of the code you need to do it inside of the guide. Don't forget your keys!

Need Something Different?

We know that data isn't always clean and simple.
Have a look through these topics if you can't see what you are looking for.