Intro to Programming and Data Science (Fall 2021)/Twitter authentication setup

From CommunityData
Twitter.png

Things you will need before you start:

Get a Twitter Account and Link It to a Mobile Phone[edit]

A Twitter account. To collect tweets from Twitter, you need a Twitter account. If your Twitter profile doesn't have your current mobile number associated with it, you will need to add your mobile number in order to create your new app as part of the process.

Apply to be a Twitter Developer[edit]

To collect tweets, you need to be approved by Twitter to be a developer. Follow each of these steps:

1. Sign in to Twitter and go to the Twitter development homepage: https://developer.twitter.com/en/portal/petition/use-case

2 Choose "Academic" and then "Student" for the two options, and then "Get Started".

Twitter signup.png

3 On the next page, under "what would you like us to call you", put "Purdue_student" (or use your name if you'd like). Enter your location as United States, and your coding experience as "No experience".

4 Next, Twitter will ask you about your plans. Please follow these instructions carefully to make sure Twitter approves your application.

In the field "In your words" put something like the following:

   I am taking an Introduction to Programming and Data Science course at Purdue university. My instructor is Jeremy Foote (jdfoote@purdue.edu). You can find details about the course at https://wiki.communitydata.science/Intro_to_Programming_and_Data_Science_(Summer_2021).

Under "The Specifics" check yes for "Are you planning to analyze Twitter data" and enter the following text:

   We are learning to download Twitter data and do basic analysis. For instance, we will try to determine whether an earthquake has happened recently. 

Uncheck the sliders for "Will your app use Tweet, Retweet, like, follow, or Direct Message functionality?" and all other options.


Capture20200126 2.PNG


5 Click "next" in the lower right then click "Next" on the review page. Finally, accept the Developer Agreement and click "Submit Application" on the next page.


6 Twitter may send an email to the account you used. Click "Confirm your email" in that email to finish setup.


If you have any trouble with the steps before this, ask for help ASAP

Confirm your developer email address[edit]

7 When you confirm in the email, you will arrive at https://developer.twitter.com/en/portal/projects-and-apps. On that page, click "Create app" under "Standalone Apps".

8 Give your app a name

App name: "COM 674 Sample <Your_First_and_Last_Name>"

and click next.


Generate and copy your individual, private, unique Twitter developer credentials[edit]

9 In the next step, you will access Twitter credentials, which will let you authenticate with Twitter in python.

You need unique, private credentials to collect tweets. You will be pasting these credentials into your Python code. Be sure if you share your Python code, you ***do not** share your unique developer credentials.

When you created your app, it should have generated the Consumer API and API secret keys. These are two long strings labeled "API key" and "API secret key". You should copy and paste those into a text file on your desktop.

10 Click the name of your app on the left-hand side and then click "Keys and tokens" on the top. Finally, click "Generate" under "Access Token and Secret". This will open a modal with two new strings called "Access Token" and "Access Token Secret". Copy these two keys to the same file and close the modal.

Access token.png

You will need all four of these strings in order to have your Twitter application work.

Keep this material secret. Your access token and access token secret will allow anybody who has it to post to Twitter as you and to control your account. It is equivalent to your Twitter username and password so please be as careful with it as you would be with your Twitter password! If you accidentally let it out into the world, then go to your application's key's and tokens page and "Regenerate" all of the tokens. This will invalidate the old ones (like resetting your password).

Other documentation[edit]

Note that some of these links may be outdated as Twitter begins to move to v2 of the API. Feel free to edit the wiki to update them

Explore how Tweets are structured

We'll be working with TWO different Twitter APIs, "Standard Search" and "Realtime."

More about the using the Twitter Search API :

For this workshop, we'll be working with the "Standard Search", the most limited of Twitter Search API options

This page has some helpful intel about modifying Standard Search parameters (including sample request and response):

Using the Twitter Realtime API :


More about the developer credentials you just generated: