2013-10-12 47 views
0

嘿,我正在開發一個Java桌面應用程序。我必須使用twitter4j 3.0.5通過主題標籤搜索推文。我對身份驗證和搜索推文沒有任何問題,但存在一些問題: 我已經使用topsy.com測試了我的搜索結果,並且我看到我收到了很少的推文或沒有推文。像#jobbingfest有大約500微博,但我發現它空... 的intrest件事:Twitter.search(查詢)文件說twitter4j 3.0.5搜索問題

Returns tweets that match a specified query. This method calls http://search.twitter.com/search.json 

該API返回JSON這樣

{"errors": [{"message": "The Twitter REST API v1 is no longer active. Please migrate to API v1.1. https://dev.twitter.com/docs/api/1.1/overview.", "code": 68}]} 

我有點困惑...爲什麼我能夠得到推文,如果該資源不再可用?

我想了解這個問題,但沒辦法......我不得不在這裏寫下求救信息:p。

非常感謝! Licio。

PS。對不起,但也許我的英語不太好...

pps。檢索超過100個推文我用這樣做是正確的?

List<MioStatus> listaStatus = null; 
try { 
    listaStatus = new ArrayList<MioStatus>(); 
    result = twitter.search(query); 
    while(result.nextQuery() != null){ 
     for (Status status : result.getTweets()) { 
      if(status.isRetweet()){ 
       listaStatus.add(new MioStatus(status.getId(), true, "RT " + status.getRetweetedStatus().getText(), status.getUser(), status.getGeoLocation(), status.getRetweetCount(), status.getCreatedAt())); 
      }else{ 
       listaStatus.add(new MioStatus(status.getId(), true, status.getText(), status.getUser(), status.getGeoLocation(), status.getRetweetCount(), status.getCreatedAt())); 
      } 
     } 
     result = twitter.search(result.nextQuery()); 
    } 
+0

http://stackoverflow.com/questions/17887984/is-it-possible-to-get-more-than-100-tweets/25069446#25069446 請參閱第5評論它是非常有用的:) –

回答

0

Twitter REST API v1不再有效。你無法用它來獲取高音揚聲器的數據。 From the site

的REST API的版本1現在已經過時,並會停止運作在未來幾個月 。今天遷移到版本1.1。

然而,API 1.1 supports JSON only,下降XML,Atom和RSS支持。

在你的代碼

同樣,你在下面的碎片調用nextQuery()兩次(閱讀評論):

while(result.nextQuery() != null){ // you are calling nextQuery() but 
            //you should call hasNext() boolean check 
     for (Status status : result.getTweets()) { 
      // do whatever you were doing 

     } 
     result = twitter.search(result.nextQuery()); 
        // you are calling nextQuery() here, so no need to call 
        //in while conditional check 
     } // while ends here 
+0

你是對的!但是: 1)twitter4j是API 1.1兼容 2)我沒有問題得到推文 - 一點都沒有。 – 0pipe0

+0

更新了答案 – Sage

+0

哦......太棒了!沒見過hasNext()...... -.-日Thnx – 0pipe0

0

確定我得到的東西......只是改變了分配的Twitter一樣,

Twitter twitter = TwitterFactory.getSingleton(); 

不要問我爲什麼,我使用MVC,應該是一樣在地圖上保存一個實例,但... 現在的問題是......「老推文在哪裏?」 setSince()是無用的。 Twitter限制?