【问题标题】:Pakistan Twitter Stream Latitude and Longitude box巴基斯坦推特流经纬度框
【发布时间】:2014-10-23 03:05:35
【问题描述】:

我想按位置和语言过滤 twitter 流。但面临错误。

我使用了链接中提到的位置参数 Passing Longitude and Latitude in Twitter Streaming API of Pakistan

错误: 7924 [Twitter Stream consumer-1[Establishing connection]] WARN twitter4j.TwitterStreamImpl - 角色不接受参数。 406:当请求中指定了无效格式时,由 Search API 返回。

当一个或多个参数不适合资源时由 Streaming API 返回。例如,track 参数会在以下情况下抛出此错误:

track 关键字太长或太短。

指定的边界框无效。

没有为过滤的资源定义谓词,例如,既不跟踪也不跟随 参数定义。

无法读取关注用户ID。

未找到过滤器参数。至少需要一个参数:跟踪轨道位置

    LinkedBlockingQueue<Status> queue = new LinkedBlockingQueue<Status>(1000);
    SpoutOutputCollector _collector = collector;
    StatusListener listener = new StatusListener() {

        @Override
        public void onStatus(Status status) {
            System.out.println(status.getLang());
            System.out.println(status.getPlace());
            System.out.print(status.getText());
        }

        @Override
        public void onDeletionNotice(StatusDeletionNotice sdn) {
        }

        @Override
        public void onTrackLimitationNotice(int i) {
        }

        @Override
        public void onScrubGeo(long l, long l1) {
        }

        @Override
        public void onException(Exception e) {
        }

        @Override
        public void onStallWarning(StallWarning arg0) {
            // TODO Auto-generated method stub

        }

    };


    TwitterStreamFactory fact = new TwitterStreamFactory(new ConfigurationBuilder().setUser(_username).setPassword(_pwd).build());
    TwitterStream _twitterStream = fact.getInstance();
    _twitterStream.addListener(listener);

    ArrayList<Long> follow = new ArrayList<Long>();
    ArrayList<String> track = new ArrayList<String>();

    long[] followArray = new long[follow.size()];
    String[] trackArray = track.toArray(new String[track.size()]);

    /**
    * Upper/northern latitude that marks the
    * upper bounds of the geographical area
    * for which tweets need to be analysed.
    */
    double northLatitude = 35.2;
    /**
    * Lower/southern latitude. Marks the lower bound.
    */
    double southLatitude = 25.2;
    /**
    * Eastern/left longitude. Marks the left-side bounds.
    */
    double eastLongitude = 62.9;
    /**
    * Western/right longitude. Marks the right-side bounds.
    */
    double westLongitude = 73.3;


    double bb[][] = {{eastLongitude, southLatitude}
    ,{westLongitude, northLatitude}};


    _twitterStream.filter(new FilterQuery(0, followArray,trackArray,bb,new String[]{"en-US"}));


     .

请帮我看看我哪里错了?

【问题讨论】:

  • 寻求调试帮助的问题(“为什么这段代码不起作用?”)必须包括所需的行为、特定的问题或错误以及重现它所需的最短代码在问题本身。没有明确的问题陈述的问题对其他读者没有用处。见How to create a Minimal, Complete, and Verifiable example
  • 我已经上传了部分代码。因为这段代码在 Storm 中使用。而且 Storm 代码太大。我的问题是,FilterQuery 发送位置无效的错误。但我已经提到了位置边界框。你明白我的意思了吗?
  • @IshwarLal 你收到来自巴基斯坦的推文了吗?你在跟随数组中添加了什么?
  • @kashifmehmood 我已将它们留空,如上面在代码中所写。

标签: java twitter location latitude-longitude


【解决方案1】:

再次尝试阅读Passing Longitude and Latitude in Twitter Streaming API of Pakistan

它清楚地表明为了正确给出框坐标,您需要将它们的格式设置为 bottom-left-longitude, bottom-left-latitude, top-right-longitude, top-right-latitude

意思是西、南、东、北。

你有:

double locationsPakistan[][] = {{eastLongitude, southLatitude}
    ,{westLongitude, northLatitude}};

试试:

double locationsPakistan[][] = {{westLongitude, southLatitude}
    ,{eastLongitude, northLatitude}};

更新

根据您在代码编辑后的评论,您现在拥有:

double northLatitude = 35.2;
double southLatitude = 25.2;
double eastLongitude = 62.9;
double westLongitude = 73.3;

double bb[][] = {{eastLongitude, southLatitude},{westLongitude, northLatitude}};

您正在混淆东/西左/右

您的 cmets 显示为“东/左经度。标记左侧边界。

东是右侧边界。 同样,West 是 left 的边界。 西应该是

这样做:

double northLatitude = 35.2;
double southLatitude = 25.2;
double westLongitude = 62.9;
double eastLongitude = 73.3;

double bb[][] = {{westLongitude, southLatitude},{eastLongitude, northLatitude}};

【讨论】:

  • 我已经完成了这些更改,但仍然是同样的错误。我在我的问题中更新了代码。现在你可以运行代码了。但是需要配置twitter api。
  • 谢谢。现在它工作正常。我能够获得巴基斯坦推特流
  • 你收到来自巴基斯坦的推文了吗?你在跟随数组中添加了什么?
  • @kashifmehmood 我相信你的问题是针对@ishwar?
  • @kashifmehmood 我只是指出了修复方法。我从未使用过代码...:/您可能应该将您的评论添加到原始问题,否则我认为 ishwar 不会看到它...
猜你喜欢
  • 1970-01-01
  • 2014-02-10
  • 2014-04-02
  • 2020-11-07
  • 2016-01-13
  • 2023-03-16
  • 2021-10-10
  • 2013-09-09
  • 2015-06-10
相关资源
最近更新 更多