简体   繁体   中英

twitter4J - how to write tweets into csv file

I am using twitter4j to extract tweets from twitter. i want to know after i retrieve tweets, how can i write those tweets into csv file? Many thanks!

 package test;
    import twitter4j.*;
    import twitter4j.conf.ConfigurationBuilder;
    import java.io.IOException;
    import java.sql.*;
    import java.util.Calendar;
    import java.io.FileWriter;
    public class test {
        public static void main(String[] args) throws TwitterException, IOException, ClassNotFoundException, IllegalAccessException, InstantiationException, SQLException 
        {
            ConfigurationBuilder cb = new ConfigurationBuilder();
            cb.setDebugEnabled(true)
                    .setOAuthConsumerKey("XXX")
                    .setOAuthConsumerSecret("XXX")
                    .setOAuthAccessToken("XX")
                    .setOAuthAccessTokenSecret("XX");
            TwitterFactory tf = new TwitterFactory(cb.build());
            Twitter twitter = tf.getInstance();
            Query query = new Query("your keywords");
            query.setCount(200);
            query.geoCode(new GeoLocation(XX, XXX), 200, Query.KILOMETERS);
            QueryResult result = twitter.search(query);
    }
    }

I have found OpenCSV to be an excellent CSV library for Java. It's open source and in Maven Central .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM