twitter4J - 如何将推文写入csv文件

时间:2013-06-28 03:36:39

标签: java csv twitter4j

我正在使用twitter4j从twitter中提取推文。我想知道在我检索推文之后,我怎样才能将这些推文写入csv文件?非常感谢!

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

1 个答案:

答案 0 :(得分:0)

我发现OpenCSV是一个优秀的Java CSV库。它是开源的in Maven Central