9
除了推文的整個JSON,我需要檢索包含許多信息(可以從某些Tweet.getX()方法中容易檢索)的推文列表。如何在Twitter4j中使用其完整的JSON獲取推文
我無法弄清楚如何獲取屬於QueryResult的推文的JSON。任何人都可以幫助我?
除了推文的整個JSON,我需要檢索包含許多信息(可以從某些Tweet.getX()方法中容易檢索)的推文列表。如何在Twitter4j中使用其完整的JSON獲取推文
我無法弄清楚如何獲取屬於QueryResult的推文的JSON。任何人都可以幫助我?
通過將對象上的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);
}
}
非常感謝,比爾!說「DataObjectFactory.getRawJSON(鳴叫)」導致Twitter API的另一個查詢,對吧?通過檢索到的推文的某些屬性無法實現,是嗎?謝謝,Andrea – andreaxi 2012-10-17 06:47:12
@andreaxi不幸的是,我不認爲JSON字符串被保存爲Tweet對象的一部分。 – 2012-10-17 10:59:30
那麼,我會找到其他方法(也許獲得JSON,然後解析它以獲取我需要的信息:所以只需查詢JSON,以及解析JSON的一些工作)。謝謝,比爾。 – andreaxi 2012-10-17 12:26:10