Simple tutorial I am following using direct authentication, searchTwitter("") does return tweets.
library(twitteR)
library(plyr)
library(tm)
library(httr)
library(wordcloud)
library(RColorBrewer)
reqURL <- "https://api.twitter.com/oauth/request_token"
accessURL <- "https://api.twitter.com/oauth/access_token"
authURL <- "https://api.twitter.com/oauth/authorize"
apiKey <- "my input"
apiSecret <- "my input"
setup_twitter_oauth(api_key,api_secret,access_token,access_token_secret)
tweets <- searchTwitter("#Trump", n=100)
tweets.text = laply(tweets,function(t)t$getText())
tweet.corpus = Corpus(VectorSource(tweets.text))
tdm = TermDocumentMatrix(
tweet.corpus,
control = list(
removePunctuation=FALSE,
stopwords = c("Trump","trump","donald","Donald", stopwords("english")),
removeNumbers= TRUE)
)
m = as.matrix(tdm)
word_freqs = sort(rowSums(m), decreasing = TRUE)
dm = data.frame(word=names(word_freqs), freq = word_freqs)
wordcloud(dm$word, dm$freq, random.order = FALSE, colors = brewer.pal(8, "Dark2"))
This is the error i get and I have tried many variations of nearly every aspect of the code. Can anyone help me?
Error in simple_triplet_matrix(i = i, j = j, v = as.numeric(v), nrow = length(allTerms), : 'i, j, v' different lengths In addition: Warning messages: 1: In mclapply(unname(content(x)), termFreq, control) : all scheduled cores encountered errors in user code 2: In simple_triplet_matrix(i = i, j = j, v = as.numeric(v), nrow = length(allTerms), : NAs introduced by coercion