You can access Twitter data for your projects using the Twitter API. To begin, you'll need to apply for a developer account with your Twitter account at https://developer.twitter.com/en/apply-for-access

Once you click apply, you'll be prompted to select your use case. Under Hobbyist, select Exploring the API.

After confirming your contact details, you'll be asked to describe how you'll be using the Twitter API. Enter in information as applicable. If you're planning to use the API for other projects beyond this one, you may want to include that information here for the future.

After confirming your information and agreeing to terms of service, you'll click Submit Application. Applications are usually approved fairly quickly, usually within a few minutes. 

Create a Project

When you log into the developer portal, you'll see your developer dashboard. Here you can access all of your account information and documentation.

In order to pull from the Twitter API, you need to create a Project. At the bottom of the Dashboard page, click on New Project and then complete the information about your Project.

Each Project has an App, which stores your API keys and access points.

Add an App to the Project your just created. Enter your desired name for your App and then click Complete.

After you've created the Project and App, you can access the Project page which supplies Usage stats and allows access to your App. 

If you click on the App Settings button (the cog wheel), you can adjust access settings for the App and access your Authentication tokens.

Do not share your Twitter API Authentication tokens with anyone!

Keep Your Secrets Secret

The project's code needs access to your Twitter API Authorization tokens. To keep this information secret, but still accessible, you can enter this information into a file called secrets.py.

secrets = {
    'ssid' : 'insert your network name here',
    'password' : 'insert your network password here',
    'timezone' : "America/New_York", # http://worldtimeapi.org/timezones
    'twitter_api_key' : 'insert your twitter api key here',
    'twitter_secret_key' : 'insert your twitter secret key here',
    'bearer_token' : 'insert your bearer token here'
    }

This guide was first published on Oct 06, 2020. It was last updated on Oct 06, 2020.

This page (Setting up the Twitter API and secrets.py) was last updated on Oct 23, 2021.

Text editor powered by tinymce.