R 中 streamR 和 twitteR 包收到的推文差异
Difference in tweets received by streamR and twitteR packages in R
我正在尝试根据 Twitter 中的特定词检索推文。我在 R 中同时使用了 twitteR 和 streamR 包。
为了使用 twitteR 访问推文,我使用 searchTwitter("love", n=50)
而当我使用 streamR 包时,我使用 filterStream("tweets.json", track = c("love"), timeout = 30, oauth = my_oauth)
然而,对于我尝试过的几乎所有搜索词,searchTwitter returns 推文多得多,而 filterStream 无法获得那么多。
可能的原因是什么?
您的 timeout = 30
选项很可能是这里的罪魁祸首。 filterStream()
在 timeout
选项中指定的持续时间内访问 Twitter 流 API。来自timeout
的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 (6-9 days) 中可用的 Twitter 历史记录,直到达到 n=50
选项中指定的最大推文数量.所以这应该会产生 50 条推文。
streamR
和 twitteR
包用于不同的事情:http://pablobarbera.com/blog/archives/1.html 如果你想访问流,请使用 streamR
,如果你想访问 Twitter history 使用 twitteR
包。两个套餐相辅相成。
我正在尝试根据 Twitter 中的特定词检索推文。我在 R 中同时使用了 twitteR 和 streamR 包。
为了使用 twitteR 访问推文,我使用 searchTwitter("love", n=50)
而当我使用 streamR 包时,我使用 filterStream("tweets.json", track = c("love"), timeout = 30, oauth = my_oauth)
然而,对于我尝试过的几乎所有搜索词,searchTwitter returns 推文多得多,而 filterStream 无法获得那么多。
可能的原因是什么?
您的 timeout = 30
选项很可能是这里的罪魁祸首。 filterStream()
在 timeout
选项中指定的持续时间内访问 Twitter 流 API。来自timeout
的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 (6-9 days) 中可用的 Twitter 历史记录,直到达到 n=50
选项中指定的最大推文数量.所以这应该会产生 50 条推文。
streamR
和 twitteR
包用于不同的事情:http://pablobarbera.com/blog/archives/1.html 如果你想访问流,请使用 streamR
,如果你想访问 Twitter history 使用 twitteR
包。两个套餐相辅相成。