package kr.co.swh.lecture.opensource.twitter; 

import java.util.ArrayList;

import twitter4j.Query;
import twitter4j.QueryResult;
import twitter4j.Status;
import twitter4j.Twitter;
import twitter4j.TwitterException;
import twitter4j.TwitterFactory;
import twitter4j.conf.ConfigurationBuilder;

/**
 * <pre>
 * kr.co.swh.lecture.opensource.twitter 
 * TwitterBasic.java
 *
 * 설명 :	https://github.com/Twitter4J/Twitter4J
 * </pre>
 * 
 * @since : 2019. 12. 13.
 * @author : tobby48
 * @version : v1.0
 */
public class TwitterBasic {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		String consumerKey = "xx";
        String consumerSecret = "xx";
        String acessToken = "xx";
        String acessTokenSecret = "xx";

        ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
        configurationBuilder.setDebugEnabled(true)
                .setOAuthConsumerKey(consumerKey)
                .setOAuthConsumerSecret(consumerSecret)
                .setOAuthAccessToken(acessToken)
                .setOAuthAccessTokenSecret(acessTokenSecret);
        TwitterFactory tf = new TwitterFactory(configurationBuilder.build());
        Twitter twitter = tf.getInstance();
        
        
        Query query = new Query();
        query.setLang("ko");
        query.setQuery("손흥민");
        query.setSince("2019-09-28");
        
        QueryResult queryResult = null;
		try {
			queryResult = twitter.search(query);
		} catch (TwitterException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        
        ArrayList<Status> result = new ArrayList<>();
        for (Status status : queryResult.getTweets()) {
            result.add(status);
        }
        
        for(Status s : result) {
        	System.out.println(s);
        	//	VO 클래스로 객체형태로 변환하여 다양하게 활용
        }
	}
}
