Last active
August 30, 2017 14:43
-
-
Save CateGitau/d1c2b7d4244eb732b5ed6cad8bcf16f6 to your computer and use it in GitHub Desktop.
Twitter data Mining in R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#install required packages | |
install.packages("twitteR") | |
install.packages("RCurl") | |
install.packages("httr") | |
install.packages("devtools") | |
devtools::install_github("r-lib/httr") | |
#Load necessary packages | |
library(twitteR) | |
library(RCurl) | |
library(base64enc) | |
#Go to http://dev.twitter.com/apps/new to create an app and get values | |
# for these credentials, which you'll need to provide in place of these | |
# empty string values that are defined as placeholders. | |
# See https://dev.twitter.com/docs/auth/oauth for more information | |
# on Twitter's OAuth implementation. | |
Access_token <- "" | |
Access_token_secret <- "" | |
consumer_key <- "" | |
consumer_secret <- "" | |
#Calling twitteR OAuth function | |
setup_twitter_oauth(consumer_key,consumer_secret,Access_token,Access_token_secret) | |
#Extracting Trends using getTrends Function | |
KE_WOE_ID = 23424863 | |
current_trends <- getTrends(KE_WOE_ID) | |
View(current_trends) | |
#Get Tweets using userTimeline function | |
tweets <- userTimeline("so and so", 50) | |
#Get tweets from a certain trending topic | |
IEBC_Tweets <- searchTwitter("IEBC", n=100, lang = "en") | |
#convert the tweets into a df | |
tweets.df <-twListToDF(IEBC_Tweets) | |
dim(tweets.df) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment