Can I request/filter the twitter streaming api to return only tweets with geotags?
我正在使用twitter4j库访问公共twitter流。我正在尝试制作一个包含地理标记的推文的项目,我需要收集大量的推文进行测试。
现在,我从Twitter获得未经过滤的流,并且只保存带有地理标签的推文。不过这很慢,因为VAST大多数推文都没有地理标签。我希望Twitter流仅向我发送带有地理标记的推文。
我尝试使用此问题中提到的方法,其中使用大小为360 * 180 *的边界框进行过滤,但这对我不起作用。使用该过滤器时,我没有收到任何错误,但我仍然获得了99%的无地理标签的推文。这是我的做法:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true) .setOAuthConsumerKey("censored") .setOAuthConsumerSecret("censored") .setOAuthAccessToken("censored") .setOAuthAccessTokenSecret("censored"); TwitterStream twitterStream = newTwitterStreamFactory(cb.build()).getInstance(); StatusListener listener = new MyStatusListener(); twitterStream.addListener(listener); //add location filter for what I hope is the whole planet. Just trying to limit //results to only things that are geotagged FilterQuery locationFilter = new FilterQuery(); double[][] locations = {{-180.0d,-90.0d},{180.0d,90.0d}}; locationFilter.locations(locations); twitterStream.filter(locationFilter); twitterStream.sample(); |
关于为什么我仍然会收到没有地理标记的推文的任何建议?
编辑:我只是重新阅读了twitter4j javadoc,它向Twitter流添加了过滤器,它说:"默认访问级别允许多达200个跟踪关键字,400个关注用户ID和10个1度位置框。"那么边界框可能只有1度宽?这与我遇到的原始信息不同。那是我的问题吗?我的过滤器请求太大,因此被忽略了吗?尝试使用它时没有出现任何错误。
从过滤器流中获取,然后用示例流覆盖它。
删除最后一行: