twitter4j how to get only statuses with location d

2019-02-16 03:31发布

问题:

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();