Twitter is as much a delight for tweeple (people using Twitter to tweet) as it is for data scientists. The APIs and the documentation are well updated and easy to use. Let us get started with the APIs.

Twitter has one of easiest yet most powerful set of APIs available of any social network out there. These APIs have been used by Twitter itself and data scientists to understand the dynamics of the Twitter world. Twitter APIs make use of four different objects, namely:

The preceding objects from the Twitter APIs have been explained at length on the website https://dev.twitter.com/. We urge readers to go through it to understand the objects and APIs even better.

Twitter has libraries available in all major programming languages/platforms. We will be making use of TwitteR, that is, Twitter's library for R.

Now that we have enough background about Twitter and its API objects, let us get our hands dirty. The first step when starting to use the APIs is to inform Twitter about your application. Twitter uses the standard Open Authentication (OAuth) protocol for authorizing a third party app. OAuth uses an application's consumer key, consumer secret, access token, and access token secret to allow it to use APIs and data of the connected service.

The following quick steps will set us up for the game:

  1. Go to Twitter's Application Management Console at https://apps.twitter.com/ and log in with your credentials or create an account if you don't have one.
  2. Click on Create New App and fill in the details for the app's name, website, and so on. For our purposes, we will name our app TwitterAnalysis_rmre. For callback URL use http://127.0.0.1:1410 to point back to your local system. You may choose any other port number as well.
  3. Click on Create your Twitter Application to complete the process. Your Application Management Console would look like the following screenshot:
    Registering the application

    The Twitter application page

Congratulations, your app is created and registered with Twitter. But before we can use it, there's one more piece to it. We need to create access tokens, and to do that we perform the following steps.

We will be using the same application for this as well as in the coming chapter. Make a note of the consumer key, consumer secret, access token and access secret; we will need these in our application.