twitter4j how to get only statuses with location data from a twitter stream

心不动则不痛 提交于 2019-11-30 20:56:42

问题


I'm getting high numbers of "onTrackLimitationNotice". I'd like to narrow my predicate by only searching for statuses with geo location, but all geo locations? Can this be done? Im coding in Processing, using twitter4j-2.2.6.

EDIT: it was an answer... moved.


回答1:


i found that querying the stream for a global bounding box, returns only status withs geo location. So this worked:

// cb is an instace of ConfigurationBuilder
TwitterStream twitter = new TwitterStreamFactory(cb.build()).getInstance();
FilterQuery filtro = new FilterQuery();    
double[][] bb= {{-180, -90}, {180, 90}};
filtro.locations(bb);
twitter.addListener(listener);
twitter.filter(filtro);

returning only tweets with location info.




回答2:


Not an answer but a Simple workaround:

I know most of people don't have GPS enabled when they tweet and others would not like to share their location!

But they are still sharing their location!! Guess how? On their profiles! Their hometown, their country is mostly visible, which can give you an approximate location of where the tweet came from! You can query for the user's profile and thus his/her location using the Rest API

twitter.showUser(userScreenName).getLocation();



来源:https://stackoverflow.com/questions/12540223/twitter4j-how-to-get-only-statuses-with-location-data-from-a-twitter-stream

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!