Example usage for twitter4j Twitter getHomeTimeline

List of usage examples for twitter4j Twitter getHomeTimeline

Introduction

In this page you can find the example usage for twitter4j Twitter getHomeTimeline.

Prototype

ResponseList<Status> getHomeTimeline() throws TwitterException;

Source Link

Document

Returns the 20 most recent statuses, including retweets, posted by the authenticating user and that user's friends.

Usage

From source file:twitterrest.GetHomeTimeline.java

License:Apache License

public static void main(String[] args) {
    try {/*from w ww.  j  a  v a 2s  .com*/
        // ?
        Configuration configuration = new ConfigurationBuilder().setOAuthConsumerKey(CONSUMER_KEY)
                .setOAuthConsumerSecret(CONSUMER_SECRET).setOAuthAccessToken(ACCESS_TOKEN)
                .setOAuthAccessTokenSecret(ACCESS_TOKEN_SECRET).build();
        Twitter twitter = new TwitterFactory(configuration).getInstance();
        User user = twitter.verifyCredentials();
        List<Status> statuses = twitter.getHomeTimeline();
        System.out.println("Showing @" + user.getScreenName() + "'s home 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);
    }
}

From source file:views.MeetingRoomPanel.java

public void initTimeline() {
    timelineFrame = new JFrame("@SIM_IST Timeline");

    timelineFrame.setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();

    timelineTweets = new JTextArea();
    Font font = new Font("Gotham Narrow", Font.BOLD, 12);
    timelineTweets.setFont(font);/*from   w  w  w . jav a  2  s . co m*/
    timelineTweets.setEditable(false);
    timelineScrollPane = new JScrollPane(timelineTweets);
    c.fill = GridBagConstraints.HORIZONTAL;
    c.weightx = 0;
    c.ipady = 200;
    c.gridx = 0;
    c.gridy = 0;
    c.gridwidth = 3;
    timelineFrame.add(timelineScrollPane, c);

    KeyReader keys = new KeyReader();

    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true).setOAuthConsumerKey(keys.getConsumerKey())
            .setOAuthConsumerSecret(keys.getConsumerSecret()).setOAuthAccessToken(keys.getAccessToken())
            .setOAuthAccessTokenSecret(keys.getAccessTokenSecret());
    TwitterFactory tf = new TwitterFactory(cb.build());
    Twitter twitter = tf.getInstance();
    try {
        System.out.println("timeline retreval worked");

        List<Status> statuses = twitter.getHomeTimeline();
        for (Status status : statuses) {
            timelineTweets
                    .append("@" + status.getUser().getScreenName() + " : " + status.getText() + "\n" + "\n");
            timelineTweets.setLineWrap(true);
            timelineTweets.setWrapStyleWord(true);
            timelineTweets.setCaretPosition(0);
            System.out.println("@" + status.getUser().getName() + " : " + status.getText());
        }

    } catch (TwitterException te) {
        System.out.print("timeline retreval failed");
        te.printStackTrace();
    }

    timelineFrame.pack();
    timelineFrame.setSize(600, 300);
    timelineFrame.setDefaultCloseOperation(EXIT_ON_CLOSE);
    timelineFrame.setLocationRelativeTo(null);
    timelineFrame.setVisible(true);
}