2014-03-05 65 views

回答

0

我不確定它是否可行。但是你可能會使用以下的東西。

例如,假設你是因爲直到日期分1一樣給搜索誰在2010-03-05(YYYY-MM-DD)創建

您可以創建類似下面的查詢用戶一天之後到一點,一天之後到點。由於沒有明確的字段來設定確切的日期,我想出了這個想法。然後,您應該使用分頁機制調用SearchUsers()方法。你可以在這裏探索如何實現分頁,我不記得它是如何實現的,但你可以很容易地在互聯網上找到一個樣本。試試下面的代碼,我希望它會工作:

try 
     { 
      Query query = new Query(); 
      query.setSince("2010-03-04"); 
      query.setUntil("2010-03-06"); 
      ResponseList<User> userList = twitterObj.searchUsers(query.toString(), -1); 

      for (User userItem : userList) 
      { 
       // Then here you can do whatever you want by using userItem object 
      } 

     } 
     catch (TwitterException ex) 
     { 
      // Do necessary error handling mechanism here 
     } 
+0

這不幹活的猜測searchUsers只需要用戶名或用戶名作爲參數的一部分。 – rahulserver

+0

是的,我說我不確定。這一結果也是預料之中的。無論如何,沒關係我的建議:) – mgokhanbakal

+0

沒有問題兄弟!無論如何感謝這個答案。 :) – rahulserver

0
public void tweetSearch(String queryRequest) throws IOException, TwitterException{ 
     // Create configuration builder and set key, token etc 
     ConfigurationBuilder cb = new ConfigurationBuilder(); 
       cb.setDebugEnabled(true); 
     cb.setOAuthConsumerKey("xxxxx"); 
// type your provided Consumer key and consumer secret key from twitter 
//and leave access token access secret token as blank 



cb.setOAuthConsumerSecret("xxxx"); 
    cb.setOAuthAccessToken("xxxx"); 
    cb.setOAuthAccessTokenSecret("xxxx"); 

    // Create Twitter instance 
    Twitter Twitter = new TwitterFactory(cb.build()).getInstance(); 

    // Create file writer and buffer writer 
    FileWriter fstream = new FileWriter("Twitterstream.txt",true); 
    BufferedWriter out = new BufferedWriter(fstream); 

    // Create Query object and set search string 
    Query query = new Query(""); 
      //change the date as u wish... 
      query.setSince("2014-06-12"); 
      query.setUntil("2014-06-14"); 
    query.setQuery(queryRequest); 

    // Get query result 
    QueryResult qr = Twitter.search(query); 

    // Get tweets and write in the file 
    while(qr.hasNext()){ 
     qr.nextQuery(); 
     List<Status> tweets = qr.getTweets(); 

     for (Status t: tweets){ 
       System.out.println(t.getId() + " - " + t.getCreatedAt() + ": " + t.getText()); 

      out.write("\n"+t.getId()+","); 
      out.write("\t"+t.getText()+","); 
      out.write("\t"+t.getUser()+","); 
     } 

    } 
      System.out.println("Generated Twitter Stream"); 

}