You are on page 1of 1

install.

packages("twitterR")
install.packages("ROAuth")
# also install tm and ggplot2
# Download "cacert.pem" file
download.file(url="http://curl.haxx.se/ca/cacert.pem",destfile="cacert.pem")
#create an object "cred" that will save the authenticated object that we can use
for later sessions
cred <- OAuthFactory$new(consumerKey='QyrhWkSEl6PsCo6u5KMGO6JPh',
consumerSecret='nkpldZnt5nV42nFgiUXpp8E8sZ9C2N5xQw2zf2O
sqvLE6Zkg2D',
requestURL='https://api.twitter.com/oauth/request_token
',
accessURL='https://api.twitter.com/oauth/access_token',
authURL='https://api.twitter.com/oauth/authorize')
# Executing the next step generates an output --> To enable the connection, plea
se direct your web browser to: <hyperlink> . Note: You only need to do this par
t once
cred$handshake(cainfo="cacert.pem")
save(cred, file="twitter authentication.Rdata")
load("twitter authentication.Rdata")
setup_twitter_oauth(consumer_key = 'QyrhWkSEl6PsCo6u5KMGO6JPh',
consumer_secret = 'nkpldZnt5nV42nFgiUXpp8E8sZ9C2N5xQw2zf2Osq
vLE6Zkg2D',
access_token= "1024295906-r0kzGiQd80jH7fSXjWirTwsHr60xPu0lhI
B6h1G",
access_secret="yLHtYouiplItph5W3PxI553lOAva5lxkAS8SecSJ3JJ5c
")
search.string <- "#IBlameAlcoholFor"
no.of.tweets <- 1000
tweets <- searchTwitter(search.string, n=no.of.tweets, lang="en")
#Covert tweets to dataframe
data<-twListToDF(tweets)
Tweets<- select(data, text) #text<- data$text
toSpace <- content_transformer(function(x, pattern) gsub(pattern, " ", x))
docs <- tm_map(docs, toSpace, "/")
docs <- tm_map(docs, toSpace, "@")
docs <- tm_map(docs, toSpace, "\\|")

You might also like