2012-08-15 60 views

回答

19

通過將對象上的setJSONStoreEnabled(true);設置爲TwitterFactory的構造函數,可以獲得推文的JSON。

這裏有一個完整的例子:

public static void main(String[] args) throws TwitterException { 
    ConfigurationBuilder cb = new ConfigurationBuilder(); 
    cb.setJSONStoreEnabled(true); 

    Twitter twitter = new TwitterFactory(cb.build()).getInstance(); 
    Query query = new Query("lizardbill"); 
    QueryResult result = twitter.search(query); 
    for (Tweet tweet : result.getTweets()) { 
     System.out.println(tweet.getFromUser() + ":" + tweet.getText()); 
     String json = DataObjectFactory.getRawJSON(tweet); 
     System.out.println(json); 
    } 
} 
+0

非常感謝,比爾!說「DataObjectFactory.getRawJSON(鳴叫)」導致Twitter API的另一個查詢,對吧?通過檢索到的推文的某些屬性無法實現,是嗎?謝謝,Andrea – andreaxi 2012-10-17 06:47:12

+0

@andreaxi不幸的是,我不認爲JSON字符串被保存爲Tweet對象的一部分。 – 2012-10-17 10:59:30

+0

那麼,我會找到其他方法(也許獲得JSON,然後解析它以獲取我需要的信息:所以只需查詢JSON,以及解析JSON的一些工作)。謝謝,比爾。 – andreaxi 2012-10-17 12:26:10

相關問題