List of usage examples for twitter4j TwitterObjectFactory getRawJSON
public static String getRawJSON(Object obj)
From source file:uniandes.edu.twitterreader.TwitterApp.java
/** * Reads all twetts accoding to TWITTER_QUERIES with JSON format and inserts * in MongoDB collection//from w ww. j a v a 2s . co m * * @param writesFile writes an additional file in TWEETS_PATH if true */ public void readColombiaTopics(boolean writesFile) { PrintWriter writer = null; try { if (writesFile) { writer = new PrintWriter(TWEETS_PATH, "UTF-8"); } for (String queryString : TWITTER_QUERIES) { Query query = new Query(queryString); query.setSince(QUERY_SINCE_DATE); query.setUntil(QUERY_LAST_DATE); QueryResult result; do { result = twitter.search(query); List<Status> tweets = result.getTweets(); for (Status tweet : tweets) { String jsonTweet = TwitterObjectFactory.getRawJSON(tweet); if (writesFile && writer != null) { writer.println(jsonTweet); } mongoCollection.insertOne(Document.parse(jsonTweet)); } } while ((query = result.nextQuery()) != null); } } catch (FileNotFoundException | UnsupportedEncodingException | TwitterException ex) { Logger.getLogger(TwitterApp.class.getName()).log(Level.SEVERE, null, ex); } finally { if (writesFile && writer != null) { writer.close(); } } }