2014-08-29 64 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