In the previous article, I have shown How to Create Twitter Apps for integration with R Programming. Now in this article I am going to discuss about the setup in R to fetch recent tweets. To start with you need to setup the following parameters in R:
- consumer_key <- ‘your key’
- consumer_secret <- ‘your secret’
- access_token<-‘your access token’
- access_secret <- ‘your access secret’
Read Previous Post to learn How to get the parameter values mentioned above.
Read Also:
How to Fetch Tweets from Twitter on a Specific Topic
To fetch the data from Twitter you need to type the following commands and use values of your App created earlier on twitter.
To establish the connection use setup_twitter_oauth function as shown below:
Once the connection is established use searchTwitter() function to fetch tweets on specific topic. In this tutorial I am going to fetch the tweets related to “ODD-EVEN” rule in Delhi. For demo purpose I will show how to fetch 10 recent tweets, you can change the number of tweets value as per your need.
See the code below to see How to Fetch Twitter Data in R:
As you can see in the example above in searchTwitter() function four parameters are passed which are explained as below:
- First parameter describes the value to search in Twitter, for eg: ODD-EVEN
- Second Parameter shows about the Language of tweets to fetch
- Third Parameter n=10 tells the R to fetch only 10 tweets
- Fourth Parameter resultType tell to fetch recent tweets.
In the next tutorial of Twitter Mining using R, you will learn How to Clean the Twitter Data.