R 和 twitteR - userTimeline() 函数不返回请求的推文数量

R and twitteR - userTimeline() function not returning the number of tweets requested

为什么我在使用 twitteR 包中的 userTimeline() 函数时无法获得我请求的推文数量?我现在对用户时间线的限制请求是 3200 条推文,但我只得到了其中的大约 10%...

这里有两个例子:

在此示例中 'googledevs' 帐户只有 2,000 条推文,所以我确实请求了 1000 条推文,但我仍然只有 106 条...

> library(twitteR)
> load('OAuth.RData')
> test <- userTimeline(user = 'googledevs', n=1000)
> length(test)
[1] 106

在此示例中 'FiveThirtyEight' 有 5622 条推文。所以我要了3200只拿到了317...

> library(twitteR)
> load('OAuth.RData')
> test2 <- userTimeline(user = 'FiveThirtyEight', n=3200)
> length(test2)
[1] 317

有人可以帮我解决这个问题吗? 谢谢

Twitter API 只会 return 过去一周左右的推文。参见 the documentation

"The Search API is not complete index of all Tweets, but instead an index of recent Tweets. At the moment that index includes between 6-9 days of Tweets."

您需要在 userTimeline 调用中包含 includeRts=TRUE 参数。这应该为您提供用户时间轴上推文的最大数量和 3200。

您需要在 userTimeline 调用中包含 includeRts=TRUE 参数。这将 return 最少 3200 个帖子和用户时间线上的帖子总数。

我认为问题在于,虽然它仅检索一定数量的推文,但它正在达到您设置的最大数量。它包括转推和回复。如果您将包括回复和转推选项设置为 true,您应该检索您设置的推文总数。此限制的一个很好的解决方法是 "making" 时间 windows 使用推文 ID 以及 sinceID 和 maxID 选项。