简体   繁体   中英

Twitter4j API location filter not working

I am using the Twitter4j API to connect to the public fire-hose. I am trying to get Tweets specific to locations or keywords but it just doesn't seem to work.Here's my code:

String geoInfo = "37.7833,122.4167"; //Coordinates of San Francisco
geoInfo = String.valueOf(status.getGeoLocation().getLatitude()) + "," + String.valueOf(status.getGeoLocation().getLongitude()); //Get the Lat. Long. of the tweet

FilterQuery tweetFilterQuery = new FilterQuery();
 tweetFilterQuery.locations(new double[][]{new double[]{-124.848974,24.396308},new double[]{-66.885444,49.384358}}); //USA Bounding box

I finally attach this to the stream where I want to filter

I am attaching my results as a screenshot.

The issues are that I am getting my tweets presumably from the far east as most of the tweet seem to be in Malay.

Secondly how to I set it for Indian coordinates and more specifically for a city in India.

I also want to run a multiple filter where I can get my tweets coming from say Mumbai, and have a particular keyword in them.

Output:

58761 [Thread-11-infoBolt] INFO  backtype.storm.daemon.task - Emitting: infoBolt default [Kukurilingan😩😝 (at Jalan Selakaso) — https://t.co/HilfQNa7GY, Kukurilingan😩😝(atJalanSelakaso)—https://tco/HilfQNa7GY, , , , c2016, https://t.co/HilfQNa7GY, 0, , 0]
58762 [Thread-27-top-words] INFO  backtype.storm.daemon.executor - Processing received message source: infoBolt:3, stream: default, id: {}, [Kukurilingan😩😝 (at Jalan Selakaso) — https://t.co/HilfQNa7GY, Kukurilingan😩😝(atJalanSelakaso)—https://tco/HilfQNa7GY, , , , c2016, https://t.co/HilfQNa7GY, 0, , 0]
        TopWords    DEBUG Read Values: , , 
        TopWords    DEBUG Read Values: , , , reportSentiment: 0.3999200159968007, URL : https://t.co/HilfQNa7GY
        TopWords    DEBUG EMIT Tweet Kukurilingan😩😝 (at Jalan Selakaso) — https://t.co/HilfQNa7GY, matcedEmoticon: , sentimentKey: c2016 0, reportSentiment: 0.3999200159968007
58773 [Thread-27-top-words] INFO  backtype.storm.daemon.task - Emitting: top-words default [Kukurilingan😩😝 (at Jalan Selakaso) — https://t.co/HilfQNa7GY, Kukurilingan😩😝 (at Jalan Selakaso) — https://t.co/HilfQNa7GY, , , , c2016, https://t.co/HilfQNa7GY, 0, , 0.3999200159968007]

Firstly it might be helpful to focus on one question at a time. My first observation is unless you didn't put in some code, you are doing things at the top that don't accomplish anything.

You declare geoInfo , then immediately try to replace it with the location of the tweet. What exactly are you trying to accomplish here?

The only thing tweetFilterQuery would do is filter in the US, but only if you do add this filter to the stream as you say.

You can set it for a city the same way you have it set for the US, but just change the corners of the long/lat box.

You can make it based on a keyword by adding:

`tweetFilterQuery.track(new String[]{searchingPhrase});`

EDIT Seems that you cannot filter on both location and keyword at the same time. You have to manually search within a string after you have the results.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM