Skip to content

Instantly share code, notes, and snippets.

@CateGitau
Last active August 30, 2017 14:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CateGitau/d1c2b7d4244eb732b5ed6cad8bcf16f6 to your computer and use it in GitHub Desktop.
Save CateGitau/d1c2b7d4244eb732b5ed6cad8bcf16f6 to your computer and use it in GitHub Desktop.
Twitter data Mining in R
#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