简体   繁体   English

Twitter4j API位置过滤器不起作用

[英]Twitter4j API location filter not working

I am using the Twitter4j API to connect to the public fire-hose. 我正在使用Twitter4j API连接到公共消防水带。 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. 您声明geoInfo ,然后立即尝试用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. tweetFilterQuery唯一要做的就是在美国使用过滤器,但tweetFilterQuery是您确实要按照您所说的那样将此过滤器添加到流中。

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. 获得结果后,您必须在字符串中手动搜索。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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