searchTwitter()或userTimeline()中的有限结果
我正在尝试使用searchTwitter()或userTimeline()中的有限结果,r,twitter,text-analysis,R,Twitter,Text Analysis,我正在尝试使用searchTwitter()和/或userTimeline() 我想获取TwitterrAPI允许获取的最大推文数(我相信限制在3000条左右) 但结果我得到的帖子很少(比如83或146)。我肯定有更多的帖子,当我检查该用户的时间线(通过浏览器或应用程序)时,我看到有3000多篇帖子。 下面是我得到的信息 r_stats <- searchTwitter("#ChangeToMeIs", n=2000) Warning message: In doRppAPICall("s
searchTwitter()
和/或userTimeline()
我想获取TwitterrAPI允许获取的最大推文数(我相信限制在3000条左右)
但结果我得到的帖子很少(比如83或146)。我肯定有更多的帖子,当我检查该用户的时间线(通过浏览器或应用程序)时,我看到有3000多篇帖子。下面是我得到的信息
r_stats <- searchTwitter("#ChangeToMeIs", n=2000)
Warning message:
In doRppAPICall("search/tweets", n, params = params, retryOnRateLimit = retryOnRateLimit, :
2000 tweets were requested but the API can only return 83
r\u stats我从git hub
安装library twitteR
,这一点非常重要,因为该版本来自git
而不是CRAN
比建立
setup_twitter_oauth("xxxxxxx", "xxxxx")
然后你就可以把它当作
从用户时间轴获取twitt
ut <- userTimeline('xxxx', n=2000)
ut <- twListToDF(ut)
实际上,您使用的是Twitter搜索API
,它只返回一个结果样本,而不是综合搜索
您需要的是Twitter流式API
请注意,Twitter搜索API不会返回详尽的
符合您的搜索条件的推文列表,因为推文只会
提供最近推文的示例。为了更全面的搜索,
您将需要使用Twitter流API,创建一个
结果并定期更新,或者使用可以
为你做这件事
来源:由于twitteR
将被弃用,您需要做的是安装rtweet
代码如下:
# Install and load the 'rtweet' package
install.packages("rtweet")
library(rtweet)
# whatever name you assigned to your created app
appname <- "tweet-search-app"
# api key (example below is not a real key)
key <- "9GmBeouvgfdljlBLryeIeqCHEt"
# api secret (example below is not a real key)
secret <- "ugdfdgdgrxOzjhlkhlxgdxllhoiofdtrrdytszghcv"
# create token named "twitter_token"
twitter_token <- create_token(
app = appname,
consumer_key = key,
consumer_secret = secret)
# Retrieve tweets for a particular hashtag
r_stats <- search_tweets("#ChangeToMeIs", n = 2000, token = twitter_token)
#安装并加载“rtweet”包
安装.packages(“rtweet”)
图书馆(rtweet)
#无论您为创建的应用程序指定了什么名称
appname我想你不是要找一个用户,而是要一个hastag。我是这样做的userTimeline('barackobama',n=100)
是的,在上面的例子中,我只尝试获取该关键字的结果。现在我得到了新的警告:r_stats1 length(r_stats1)[1]193
为什么我无法获取最大上限帖子?等等,我会给你我的解决方案,它运行良好。twitteR API有任何限制吗,只提供有限的数据?我读过几篇提到这一点的帖子。Ok@Mateusz1981我从Cran
安装了twitteR,之前我从GIT
安装了twitteR,并且尝试了,我看不到行为上的任何变化。但我只能收到198条推文(我猜由于日期的原因,会有一些API限制。)
R version 3.2.2 (2015-08-14)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1
locale:
[1] LC_COLLATE=Swedish_Sweden.1252 LC_CTYPE=Swedish_Sweden.1252 LC_MONETARY=Swedish_Sweden.1252 LC_NUMERIC=C LC_TIME=Swedish_Sweden.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] twitteR_1.1.9
loaded via a namespace (and not attached):
[1] bit_1.1-12 httr_1.1.0 rjson_0.2.15 plyr_1.8.3 R6_2.1.2 rsconnect_0.4.1.11 DBI_0.3.1 tools_3.2.2
[9] whisker_0.3-2 yaml_2.1.13 Rcpp_0.12.4 bit64_0.9-5 rCharts_0.4.5 RJSONIO_1.3-0 grid_3.2.2 lattice_0.20-33
# Install and load the 'rtweet' package
install.packages("rtweet")
library(rtweet)
# whatever name you assigned to your created app
appname <- "tweet-search-app"
# api key (example below is not a real key)
key <- "9GmBeouvgfdljlBLryeIeqCHEt"
# api secret (example below is not a real key)
secret <- "ugdfdgdgrxOzjhlkhlxgdxllhoiofdtrrdytszghcv"
# create token named "twitter_token"
twitter_token <- create_token(
app = appname,
consumer_key = key,
consumer_secret = secret)
# Retrieve tweets for a particular hashtag
r_stats <- search_tweets("#ChangeToMeIs", n = 2000, token = twitter_token)