For the Text Mining Module 1 Learning Labs, we’ll be using the Twitter Application Programming Interface (API) to examine public sentiment around the Common Core and Next Generation Science Standards. The Twitter API facilitates this analysis by provides companies, developers, and researchers with programmatic access to public data.
For those new to the concept of an API, our very own Raleigh, NC-based Red Hat describes an API as a means for one product or service communicate with other products and services:
APIs are sometimes thought of as contracts, with documentation that represents an agreement between parties: If party 1 sends a remote request structured a particular way, this is how party 2’s software will respond.
As Duke University’s Chris Bail notes, “APIs have become one of the most important ways to access and transfer data online— and increasingly APIs can even analyze your data as well.” Compared to screen-scraping data from web pages, which explore in Module 2 later this year, APIs are considerably easier to work with than the HTML or XML data, ensure that data is collected legally, and with R packages like rtweet, are logistically easier to work with, as we’ll see at the workshop this summer.
For a more in-depth explanation of APIs, how they work, and a preview of some of the rtweet functions we’ll be using this summer, we highly recommend reading through Chris Bail’s Application Programming Interfaces in R tutorial.
In order to use Twitter’s API, you will need to set up a Twitter developer account, which requires a have a regular twitter account. :
Apply for a developer account button.Next, you’ll be asked to select a developer account #UseCase.
For the LASER Institute, I recommend selecting Student under the Academic use case to facilitate approval.
Later, you can apply for an Academic Research account if you anticipate working with Twitter data for a future research project.
Click the blue Get started button to submit a standard application.
Provide the basic information requested and for Intended use.
Below are some suggestions below for each of the questions you’ll be asked:
In English, please describe how you plan to use Twitter data and/or APIs. The more detailed the response, the easier it is to review and approve.
Are you planning to analyze Twitter data?
Will your app use Tweet, Retweet, Like, Follow, or Direct Message functionality? Please describe your planned use of these features.
Do you plan to display Tweets or aggregate data about Twitter content outside Twitter? Please describe how and where Tweets and/or data about Twitter content will be displayed outside of Twitter.
Will your product, service, or analysis make Twitter content or derived information available to a government entity?
Read through the guidelines before submitting your applications. Sumedh Patkar has provide an excellent summary these guidelines which I’ve copied below:
Review and submit your application. Once you have submitted you can’t make changes so make sure everything is complete and correct.
Wait for an email from Twitter that should arrive in the next few days that either:
Once your application is approved you can now using the Twitter API. and proceed to the following section!
Before you can begin pulling tweets into R, you’ll first need to create a Twitter App in your developer account. This section is borrowed largely from the rtweet package by Michael Kearney, and requires that you have set up a Twitter developer account.
Follow the steps below to set up your app:
Navigate to developer.twitter.com/en/apps, click the blue button that says, Create a New App, and then complete the form with the following fields:
App Name: What your app will be called
Application Description: How your app will be described to its users
Website URLs: Website associated with app
Callback URLs: IMPORTANT enter exactly the following: `http://127.0.0.1:1410`
Tell us how this app will be used: Be clear and honestWhen you’ve completed the required form fields, click the blue Create button at the bottom
Read through and indicate whether you accept the developer terms