Section 11.2 A Token of Your Esteem: Using OAuth
Before we move forward with creating some code in R-studio, there’s an important set of steps we need to accomplish at the Twitter website.
In 2013, Twitter completed a transition to a new version of their application programming interface, or API. This new API requires the use of a technique for authorization - a way of proving to Twitter that you are who you are when you search for (or post) tweets from a software application. The folks at Twitter adopted an industry standard for this process known as OAuth. OAuth provides a method for obtaining two pieces of information - a “secret” and a “key” - without which it will be difficult if not downright impossible to work with Twitter (as well as twitteR). Here are the steps:
-
Get a Twitter account at Twitter.com if you don’t already have one.
-
Go to the development page at Twitter (https://dev.twitter.com) and sign in with your Twitter credentials.
-
Click on “My Applications.” The location of this may vary over time, but look for in a drop down list that is under your profile picture on the top right corner of the screen.
-
Click on “Create a New Application.” Fill in the blanks with some sensible answers. Where it asks for a “website” you can give your own home page. This is a required response, so you will have to have some kind of web page to point to. In contrast, the “Callback URL” can be left blank. Click submit.
-
Check the checkbox specified in the image below under settings. Your application should be set so that it can be used to sign in with Twitter.
-
You will get a screen containing a whole bunch of data. Make sure to save it all, but the part that you will really need is the “Consumer key” and the “Consumer Secret,” both of which are long strings of letters and numbers. These strings will be used later to get your application running in R. The reason these are such long strings of gibberish is that they are encrypted.
-
Also take note of the Request Token URL and the Authorize URL. For the most part these are exactly the same across all uses of Twitter, but they may change over time, so you should make sure to stash them away for later. You do not need to click on the “Create my Access Token” button.
-
Go to the Settings tab and make sure that “Read, Write and Access direct messages” is set.
You may notice on the Home->My applications screen in the dev.twitter.com interface that there are additional tabs along the top for different activities and tasks related to OAuth. There is a tab called “OAuth tool” where you can always come back to get your Consumer key and Consumer secret information. Later in the chapter we will come back to the usage of your Consumer key and your Consumer secret but before we get there we have to get the twitteR package ready to go.
