library(twitteR)
library(wordcloud)
## Loading required package: RColorBrewer
library(tm)
## Loading required package: NLP
library(plyr)
##
## Attaching package: 'plyr'
## The following object is masked from 'package:twitteR':
##
## id
consumer_key <- "XocnrW0maFEaqvLTCgB9J31tO"
consumer_secret <- "HGHrg5BEYsKbMTACUxklpmOtYx1CfFUfMGNmI2jMrEjmgVkbr2"
access_token <- "1010498701620543488-QxvfM5RFn4YZpR4MNVHDgQOGncX9ys"
access_secret <-"rYkr52HtwdQVTWKLp1F0nQ7zOgkqbwX1a04Wewl0AA0a5"
setup_twitter_oauth(consumer_key, consumer_secret, access_token, access_secret)
## [1] "Using direct authentication"
num_tweets <- 50
r_stats <- searchTwitter("#serena", n=num_tweets)
#save text
r_stats_text <- sapply(r_stats, function(x) x$getText())
#create corpus - Constructs a text document collection (corpus).
r_stats_text_corpus <- Corpus(VectorSource(r_stats_text))
r_stats_text_corpus <- tm_map(r_stats_text_corpus, function(x) iconv(enc2utf8(x), sub = "byte"))
## Warning in tm_map.SimpleCorpus(r_stats_text_corpus, function(x)
## iconv(enc2utf8(x), : transformation drops documents
r_stats_text_corpus <- tm_map(r_stats_text_corpus, content_transformer(tolower))
## Warning in tm_map.SimpleCorpus(r_stats_text_corpus,
## content_transformer(tolower)): transformation drops documents
r_stats_text_corpus <- tm_map(r_stats_text_corpus, removePunctuation)
## Warning in tm_map.SimpleCorpus(r_stats_text_corpus, removePunctuation):
## transformation drops documents
r_stats_text_corpus <- tm_map(r_stats_text_corpus, function(x)removeWords(x,stopwords()))
## Warning in tm_map.SimpleCorpus(r_stats_text_corpus, function(x)
## removeWords(x, : transformation drops documents
wordcloud(r_stats_text_corpus)

r_stats <- userTimeline("Serena", n=100) #n is The maximum number of tweets to return
me <- getUser("Serena")
me$getId() #25073877
## [1] "2860101"
getUser(2860101)
## [1] "Serena"
followersIds <- lookupUsers(me$getFollowerIDs())
length(followersIds)
## [1] 12297
followers <- me$getFollowers() ##returns a list
#followersIds[[1]]
trend <- availableTrendLocations()
head(trend)
## name country woeid
## 1 Worldwide 1
## 2 Winnipeg Canada 2972
## 3 Ottawa Canada 3369
## 4 Quebec Canada 3444
## 5 Montreal Canada 3534
## 6 Toronto Canada 4118