How to get a tweet with its full JSON in Twitter4j

孤街浪徒 提交于 2020-02-19 09:58:25

问题


I need to retrive a list of tweets, with many informations (easily retrievable from some Tweet.getX() methods) except for the tweet's entire JSON.

I can't figure out how to get the JSON of a tweet belonging from a QueryResult. Anyone can help me?


回答1:


You can get the JSON of your tweets by setting setJSONStoreEnabled(true); on the ConfigurationBuilder object that you pass to your TwitterFactory constructor.

Here's a full example:

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);
    }
}


来源:https://stackoverflow.com/questions/11968905/how-to-get-a-tweet-with-its-full-json-in-twitter4j

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!