我在 twitter4j java Api 中创建了一个 twitterStream,我想用它来跟踪用户的状态。我得到了一个用户列表,实际上是 followID。实际上,我在监听器中下载用户的状态图像。我使用以下名称保存图像:
String ImageUniqueFileName = status.getUser().getId()+"_id_"+CreateUniqueFileName();
ImageUniqueFileName = ImageUniqueFileName + ".jpg";
我注意到在保存的图像中,我得到了几个不在初始列表 followID 中的用户 ID。我追踪其他用户的 ID 是否正常?第二个问题,如何才能追踪 twitterStream 中的所有用户推文而不是最后 200 条用户推文?
TwitterStream twitterStream = new TwitterStreamFactory(cb.build()).getInstance();
twitterStream.addListener(listener);
FilterQuery fq = new FilterQuery();
// fq.track(myQueries);
fq.follow(followIDs);
twitterStream.filter(fq);
ArrayList<FilterQuery> list = new ArrayList<FilterQuery>();
list.add(fq);
最佳答案
使用follow
参数将导致匹配以下推文:
- Tweets created by the user.
- Tweets which are retweeted by the user.
- Replies to any Tweet created by the user.
- Retweets of any Tweet created by the user.
- Manual replies, created without pressing a reply button (e.g. “@twitterapi I agree”).
我认为你的假设是正确的,这可能是未知 ID 的原因。
关于获取用户的推文,您将无法使用流式 API,因为它是 Twitter 的实时 View 。但是,您也许可以使用 getUserTimeline(userId, paging)
检索推文。
有关 getUserTimeline
实际操作的简单示例,请查看 GetUserTimeline
example .
关于java - 使用 TwitterStream 过滤最后的用户推文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23648397/