The intention of this blog post is to give you start on using the TwitteR Package of R. Using this package you can do lot of analysis on social media “Twitter”. I have written an post on analyzing a Cricketer’s Century Tweets and also the need for analyzing tweets already in my blog.
Pre-Requisite tools & Environment:
We are going to explore this completely with Windows 7 and R.
Steps to follow:
Step 1:We need to use the TwitteR package and ROAuth package for accessing the tweets. As per the recommendation from Twitter its always safe to access the tweets via SSL. First we will see the code for the same.
#install the basic packages
#Initiate/Invoke the libraries
#necessary step for Windows to handle the SSL Part
Step 2: Use the OAuthFactory to setup the Credentials and start accessing data in the following way
cred <- OAuthFactory$new(consumerKey=’azbiz8LbVeA0lBUVh3c6lA‘,
After this you can notice that “handshakeComplete” is FALSE. We need to complete the handshake to get access to the TwitterAPI and its data.
Step 3: Create a handshake with twitter, for which you will get a message like the following:
To enable the connection, please direct your web browser to:
When complete, record the PIN given to you and provide it here: install.packages("ROAuth")
Once you naviage to the URL you will get a PIN which you should type in the R Console. Now you can see that we have enterered the PIN from the browser after authorizing the Application.
You can also realize that now the “handshakeComplete” has become TRUE.
Step 4: Verify the status of OAuth authentication using the following command and it should return TRUE.
Step 5: Now the next step is to start accessing the data using TwitterAPI. Let’s try to get started with accessing the User Information.
You need to make sure that you also pass the cainfo otherwise you will get an SSL Error.
Hope now we understand the steps required for accessing the Twitter data using the TwitteR Package. In this example we had shown the various attributes of the User Object retrieval. In the next post we will try to analyze some data.
Similar posts for your reference: