Can I request / filter a twit streaming api stream to return only geotagged tweets?

I use twitter4j library to access the public twitter stream. I am trying to create a project using geotagged tweets, and I need to collect a large number of them for testing.

Now I get unfiltered stream from twitter and save only tweets with geotags. This is slow because most VAST tweets do not have geotags. I want the twitter stream to send me only geotagged tweets.

I tried using the method mentioned in this question where you filter with a 360 * by 180 * bounding box, but this does not work for me. I don't get any errors when using this filter, but I still get 99% of the tweets without geotags. Here is how I do it:

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

Any suggestions on why I still get tweets without geotags?

Edit: I just re-read twitter4j javadoc about adding filters to the twitter stream and it says: "The default access level allows up to 200 keywords, 400 follow user pointers and 10 boxes with 1 degree." So, bounding boxes can only be 1 degree wide? This is different from the original information I came across. It is my problem? My filter request is too large, why is it ignored? I do not get any errors when trying to use it.

+4
source share
1 answer

getting from the filter stream, and then overwriting it with the sample stream.

delete the last line: twitterStream.sample();

+7
source

Source: https://habr.com/ru/post/1416663/


All Articles