'JAVA'에 해당되는 글 51건

  1. 2011.08.09 twitter4j 와 java 연동
2011. 8. 9. 20:20

twitter4j 와 java 연동

> 개발 환경: eclipse
> Library: twitter4j-core-2.2.4.jar/ twitter4j-core-2.2.5-SNAPSHOT.jar
> 추가파일: twitter4j.properties
> twitter4j.properties 내용:
oauth.consumerKey=dAnyJBQh1rg
oauth.consumerSecret=5Fjs36wKvExM
oauth.accessToken=34616-J40FWg6JtOji
oauth.accessTokenSecret=zblkx8s0tpWFdb


import twitter4j.Status;
import twitter4j.Twitter;
import twitter4j.TwitterException;
import twitter4j.TwitterFactory;
import twitter4j.User;

import java.util.List;

public class GetFriendsTimeline {
    /**
     * Usage: java twitter4j.examples.timeline.GetFriendsTimeline
     *
     * @param args String[]
     */
    public static void main(String[] args) {
        // gets Twitter instance with default credentials
        Twitter twitter = new TwitterFactory().getInstance();
        try {
            User user = twitter.verifyCredentials();
            List<Status> statuses = twitter.getFriendsTimeline();
            System.out.println("Showing @" + user.getScreenName() + "'s friends timeline.");
            for (Status status : statuses) {
                System.out.println("@" + status.getUser().getScreenName() + " - " + status.getText());
            }
        } catch (TwitterException te) {
            te.printStackTrace();
            System.out.println("Failed to get timeline: " + te.getMessage());
            System.exit(-1);
        }
    }
}