Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从R中单个用户的推文中获取评论_R_Twitter - Fatal编程技术网

从R中单个用户的推文中获取评论

从R中单个用户的推文中获取评论,r,twitter,R,Twitter,我收集了单个用户的推文: api_key <- "XXXX" api_secret <- "XXXX" access_token <- "XXXX" access_token_secret <- "XXXX" setup_twitter_oauth(api_key, api_secret, access_token, access_token_secret) salvini <- rtweet::get_timeline(user = "matteosalvini

我收集了单个用户的推文:

api_key <- "XXXX"
api_secret <- "XXXX"
access_token <- "XXXX"
access_token_secret <- "XXXX"
setup_twitter_oauth(api_key, api_secret, access_token, access_token_secret)

salvini <- rtweet::get_timeline(user = "matteosalvinimi", n = 3600)

api_key首先,请查看提问协议。您被降级是因为您(1)没有提供可复制的数据集,(2)在此处的其他地方问了一个问题

下面是一个快速的答案:

library(twitteR);library(dplyr); library(ROAuth)
#set API Keys; to obtain, go here: https://apps.twitter.com/ and make an application for  your twitter account

api_key <- "paste yours here"      # create a set of 'keys' & 'tokens'
api_secret <- "paste yours here"
access_token <- "paste yours here"
access_token_secret <- "paste yours here"
setup_twitter_oauth(api_key, api_secret, access_token, access_token_secret)

#grab latest tweet data
tweets1 <- searchTwitter('@oprah', n=1000)
TweetsBy1<-twListToDF(tweets1)  #convert to dataframe
TweetsBy1$account<-"Oprah"  # useful to have this

glimpse(TweetsBy1) # look at your data; the text variable is what you're after

temp<- TweetsBy1 %>% 
        group_by(created) %>%   # you will need to reformat this date variable
        summarise(numTweets=n())

TweetsBy1$text   # this is the text of the tweets

ggplot(temp, aes(created,numTweets))+geom_bar(stat="identity")+
       theme_bw()+ylab("Number of Tweets")+
       ggtitle("Number of Tweets by Date")
library(twitteR);图书馆(dplyr);图书馆(ROAuth)
#设置API密钥;要获取,请访问此处:https://apps.twitter.com/ 并为您的twitter帐户制作一个应用程序

嗨,本,谢谢你的观点。我已经插入了用于收集数据的代码。我的问题似乎没有出现在其他帖子中:如果我答对了,在你的语法中,你可以获得tweet,包括单词“@oprah”(这可能被解释为关于oprah的帖子),并使用
TweetsBy1$text
提取文本。我的意思是收集用户“matteosalvinimi”发布的每条推文的评论文本。我希望这一点现在更清楚了。@LucaCarbone这个答案可能会帮助你: