#Getting and authorizing Twitter to use Twitter feeds
setup_twitter_oauth(consumer_key, consumer_secret, access_token, access_secret)
## [1] "Using direct authentication"
# Searh free SHS in Ghana on twitter
shs<-searchTwitter("free SHS in Ghana",n= 100, lang = "en", resultType = "recent")
## Warning in doRppAPICall("search/tweets", n, params = params,
## retryOnRateLimit = retryOnRateLimit, : 100 tweets were requested but the
## API can only return 20
head(shs)
## [[1]]
## [1] "news_ghana: Free SHS; Is It Aimed At Tying Together the North South in Education? https://t.co/YSrqYRfWpE"
##
## [[2]]
## [1] "gmadinyira: Only students who wrote or re-wrote their BECE in 2017 will qualify for Free SHS - Perry Okudzeto. #Sunyani #Ghana<U+0085> https://t.co/gC11e5UVi1"
##
## [[3]]
## [1] "shammah411: RT @gmadinyira: Deputy Minister of Information, Perry Okudzeto is in the studios of #RadioBAR in #Sunyani discussing FREE SHS. #FreeSHSisHe<U+0085>"
##
## [[4]]
## [1] "gmadinyira: Deputy Minister of Information, Perry Okudzeto is in the studios of #RadioBAR in #Sunyani discussing FREE SHS. #FreeSHSisHere #Ghana"
##
## [[5]]
## [1] "Ghananewsonline: Free SHS: A Challenge to Bridging Gap in Education Between Northern and Southern Ghana https://t.co/Eyep6pnlX1 https://t.co/WgWdYGaAyz"
##
## [[6]]
## [1] "Bolga_Ghana: RT @iddinash: Was once a beneficiary somewhere early 2000's... will offer free tuition next long vac. Insha Allah.Kudos guys !!! https://<U+0085>"
# Converting the twitter feed into a vector
shs_text<-sapply(shs,function(x)x$getText())
# creating a corpus from tweets
shs_corpus<-Corpus(VectorSource(shs_text))
shs_corpus
## <<SimpleCorpus>>
## Metadata: corpus specific: 1, document level (indexed): 0
## Content: documents: 20
#cleaning the text
shs_clean<-tm_map(shs_corpus,removePunctuation)
shs_clean<-tm_map(shs_clean,content_transformer(tolower))
shs_clean<-tm_map(shs_clean,stripWhitespace)
shs_clean<-tm_map(shs_clean,removeNumbers)
removeURL <- function(x) gsub("http[[:alnum:]]*", "", shs_clean)
shs_clean<- tm_map(shs_clean, removeURL)
#wordcloud
wordcloud(shs_clean, random.order = F, colors=rainbow(20))