我正在尝试根据 Twitter 中的特定词检索推文。我在 R 中同时使用了 twitteR 和 streamR 包。
为了使用 twitteR 访问推文,我使用 searchTwitter("love", n=50)
而当我使用 streamR 包时,我使用 filterStream("tweets.json", track = c( "love"), timeout = 30, oauth = my_oauth)
然而,对于我尝试过的几乎所有搜索词,searchTwitter 都会返回更多推文,而 filterStream 无法获得那么多。
可能是什么原因?
最佳答案
您的 timeout = 30
选项很可能是这里的罪魁祸首。 filterStream()
在 timeout
选项中指定的持续时间内访问 Twitter 流 API。来自 searchR
documentation 超时
:
numeric, maximum length of time (in seconds) of connection to stream. The connection will be automatically closed after this period. For example, setting timeout to 10800 will keep the connection open for 3 hours. The default is 0, which will keep the connection open permanently
这意味着带有 timeout = 30
选项的 filterStream
会监听 Twitter 流 30 秒。
searchTwitter()
搜索 API 中可用的 Twitter 历史记录 (6-9 days),直到达到 n=50
中指定的最大推文数量> 选项。所以这应该会产生 50 条推文。
streamR
和 twitteR
包用于不同的事情:http://pablobarbera.com/blog/archives/1.html如果要访问流,请使用 streamR
,如果要访问 Twitter 历史记录,请使用 twitteR
包。两个包相互补充。
关于r - R 中 streamR 和 twitteR 包收到的推文差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30056157/