List of usage examples for twitter4j JSONObject JSONObject
public JSONObject()
From source file:tiofortwitter.TioForTwitter.java
/** * @param args the command line arguments *///from w w w . j a va 2 s . c o m public static void main(String[] args) throws JSONException, IOException { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey("Gkr9iZwYDALZ16OdxMp5rubBH") .setOAuthConsumerSecret("nhEwYFfiX5qp90sLLwO2eeYMxLwb3WC120lgihrocZDPWRNcUK") .setOAuthAccessToken("94107100-572UpcOkkz9kMWGaJS8YFsIGdlmJAd2cDw8y9rOnA") .setOAuthAccessTokenSecret("ST0XtXUjYgYWKHryL2feNM0VcDQQAgrov2V7nB7hq1xBC"); TwitterFactory tf = new TwitterFactory(cb.build()); Twitter twitter = tf.getInstance(); JSONObject obj = new JSONObject(); int counterTweet = 0; FileWriter file = new FileWriter("Users\\user\\IdeaProjects\\TwitterStringMatching\\input.txt"); file.flush(); try { Query query = new Query("Satria"); QueryResult result; do { result = twitter.search(query); List<Status> tweets = result.getTweets(); for (Status tweet : tweets) { counterTweet++; System.out.println("@" + tweet.getUser().getScreenName() + " - " + tweet.getText()); obj.put("user", tweet.getUser().getScreenName()); obj.put("tweets", tweet.getText()); //Tulis file ke dalam txt try { file.write(obj.toString()); System.out.println("Successfully Copied JSON Object to File..."); System.out.println("\nJSON Object: " + obj); } catch (IOException e) { e.printStackTrace(); } } } while (counterTweet < 1000); file.close(); System.exit(0); } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to search tweets: " + te.getMessage()); System.exit(-1); } System.exit(0); }