2014-08-29 25 views
1

我想按位置和语言过滤twitter流。但面临错误。在链接中提到巴基斯坦Twitter流经纬度框

我已经使用位置参数 Passing Longitude and Latitude in Twitter Streaming API of Pakistan

错误: 7924 [Twitter的数据流的消费1建立连接] 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"})); 


    . 

请帮我,我错在哪里?

+0

问题寻求帮助调试(“**为什么不是这个代码工作的**?”)必须包括所期望的行为,一个特定的问题或错误的和必要的最短的代码在问题本身**中重现它**。没有**明确问题陈述**的问题对其他读者没有用处。请参见[如何创建最小,完整和可验证示例](http://stackoverflow.com/help/mcve)。 – DavidPostill 2014-08-29 09:02:56

+0

我已经上传部分代码。因为这个代码在Storm中使用。 Storm代码太大。我的问题是,FilterQuery发送错误的位置是无效的。但我提到了位置边界框。你明白我的观点了吗? – 2014-08-29 11:04:09

+0

@IshwarLal是否收到来自巴基斯坦的推文?你在追加数组中添加了什么? – kashifmehmood 2015-01-20 15:27:04

回答

2

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

它清楚地说为了正确给出框坐标,您需要以格式左下角 - 经度,左下 - 纬度,右上 - 经度,右上 - 纬度

这意味着西,南,东北。

您有:

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}}; 

您正在混合东/西左/右

您的意见表明这是你有“东/左经度,标志着左侧边界。

东是侧约束。 同样西方是左边边界。 西部应该是<东部。

所以做到这一点:

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

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

我已经做了这些更改,但仍然是相同的错误。我在我的问题中更新了代码。现在你可以运行代码。但需要为twitter api进行配置。 – 2014-08-30 06:46:58

+0

谢谢。现在它工作正常。我能够得到巴基斯坦推特流 – 2014-08-30 09:01:07

+0

你是否从巴基斯坦得到推文?你在追加数组中添加了什么? – kashifmehmood 2015-01-20 13:39:18