ponens
ponens

Reputation: 85

Twitter stream - location AND keywords

I am using the 'Twitter4j' library and I am just wondering if it is at all possible to return tweets within a location AND contain a certain keyword. I notice that on the official Twitter documentation it mentions this:

Bounding boxes are logical ORs. A locations parameter may be combined with track parameters, but note that all terms are logically ORd, so the query string track=twitter&locations=-122.75,36.8,-121.75,37.8 would match any tweets containing the term Twitter (even non-geo tweets) OR coming from the San Francisco area.

Which is unfortunate as it is not what I need, it's returning way too many tweets. Any idea on how I could get around this or is there something I'm missing in the library that could allow me to do it?

Library javadoc: http://twitter4j.org/en/javadoc/twitter4j/FilterQuery.html#locations

At the moment I have my filter code like this twitter.filter(new FilterQuery().locations(sydney).track(keywords));

and have also tried each on its own line: twitter.filter(new FilterQuery().locations(sydney).track(keywords));

twitter.filter(new FilterQuery().track(keywords));

Upvotes: 5

Views: 2748

Answers (2)

Sam
Sam

Reputation: 851

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

Search for all keywords, if the location you wan't doesn't match, simply discard! In this way, you can get more number of tweets atleast

Upvotes: 0

muffinista
muffinista

Reputation: 6736

Unfortunately, you are reading the documents correctly. I don't know enough about twitter4j to say if there's a method contained somewhere that will handle this for you more easily, but you can always just use a simple string comparison to see if your search terms are included in the tweet.

Upvotes: 1

Related Questions