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:edu.proyectofinal.integradorrs.services.tweets.impl.TweetsServiceImpl.java

@Override
public Collection<Status> getAllTweets(String email) {

    TwitterCredentials tc = TwitterCredentials.getInstance();
    ConfigurationBuilder cb = tc.GetCredentials(email);

    TwitterFactory tf = new TwitterFactory(cb.build());
    Twitter twitter = tf.getInstance();
    List<Status> statuses = null;
    try {/*from  www . j  a va 2 s. c  om*/
        statuses = twitter.getHomeTimeline();
    } catch (TwitterException ex) {
        Logger.getLogger(TweetsServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
    }
    Collection<Status> result = (Collection<Status>) statuses;
    return result;

}

From source file:entities.TwitterFeed.java

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

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

    timelineBack = new JButton("Back");
    timelineBack.addActionListener(this);
    c.fill = GridBagConstraints.HORIZONTAL;
    c.weightx = 0.5;/*www  . j  a  v a  2 s .  c  o m*/
    c.gridx = 1;
    c.gridy = 1;
    c.gridwidth = 1;
    timelineFrame.add(timelineBack, c);

    timelineTweets = new JTextArea();
    Font font = new Font("Gotham Narrow", Font.BOLD, 12);
    timelineTweets.setFont(font);
    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);
}

From source file:Group5.Model.java

public static List GetTimeline() throws TwitterException {
    //Your Twitter App's Consumer Key
    String consumerKey = "wK7lQLpl3t8xvIABqpgoJzYYd";

    //Your Twitter App's Consumer Secret
    String consumerSecret = "4M5TgmNfS0EKeaSqna8eHTNaNi970Plq3dynX5gvYsh848j0mj";

    //Your Twitter Access Token
    String accessToken = "829891753473892361-7jkKyXLYc6HOStzCPGjWOnVoAVNU7cd";

    //Your Twitter Access Token Secret
    String accessTokenSecret = "ATidrzRzhVqAamuMbYiskcHBPSisB9MWsCsYYY2Bec4y9";

    //Instantiate a re-usable and thread-safe factory
    TwitterFactory twitterFactory = new TwitterFactory();

    //Instantiate a new Twitter instance
    Twitter twitter = twitterFactory.getInstance();
    //setup OAuth Consumer Credentials
    twitter.setOAuthConsumer(consumerKey, consumerSecret);

    //setup OAuth Access Token
    twitter.setOAuthAccessToken(new AccessToken(accessToken, accessTokenSecret));
    List<Status> statuses = twitter.getHomeTimeline();
    System.out.println("Showing home timeline.");
    for (Status status : statuses) {
        System.out.println(status.getUser().getName() + ":" + status.getText());
    }//  ww  w  .  jav  a2  s . c  o  m
    return statuses;
}

From source file:Jums.SearchTweet.java

public void main(PrintWriter out) {
    try {/*from w w  w .j a va 2  s .c om*/
        ConfigurationBuilder cb = new ConfigurationBuilder();
        cb.setDebugEnabled(true);
        cb.setOAuthConsumerKey(CONSUMERKEY);
        cb.setOAuthConsumerSecret(CONSUMERSECRET);
        cb.setOAuthAccessToken(TOKEN);
        cb.setOAuthAccessTokenSecret(TOKENSECRET);
        Twitter tw = new TwitterFactory(cb.build()).getInstance();
        User user = tw.verifyCredentials();
        List<Status> statuses = tw.getHomeTimeline();

        for (Status s : statuses) {

        }

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:junit.org.rapidpm.module.iot.twitter.TwitterInitApp.java

License:Apache License

public static void main(String[] args) throws TwitterException {
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true).setOAuthConsumerKey("DI0UZvexwirEJ1wl5sw9Vfqx3")
            .setOAuthConsumerSecret("NQ0Zumw7Li1XbuwzrNHOKquznBgmAJo1sPAoqiNMShqgFufqip")
            .setOAuthAccessToken("2440296835-4dmuWPOLYUgLjn9ddcXpuloOgDAPO1W0Y5NZSg7")
            .setOAuthAccessTokenSecret("X9QYzlDKURIxGZbFWoZ7NdvhcFurBfEUVHMTLxtBSrU2x");

    TwitterFactory tf = new TwitterFactory(cb.build());
    Twitter twitter = tf.getInstance();

    twitter.getHomeTimeline().forEach(s -> System.out.println("s.getText() = " + s.getText()));

}

From source file:mitwitter.MiTwitter.java

/**
 * @param args the command line arguments
 *///from  www.j av  a  2  s . co  m
public static void main(String[] args) throws TwitterException {
    // TODO code application logic here

    //camobios

    Twitter twitter = new TwitterFactory().getInstance();

    //CODIGO CAMBIAR ESTADO
    Status miStatus = twitter.updateStatus("Tercer ejemplo");//cambia el estado de twitter
    System.out.println(miStatus.getText());

    //CODIGO TIMELINE
    List<Status> statuses = twitter.getHomeTimeline();
    System.out.println("Showing home timeline.");//aparecen los ultimos twitts
    for (Status status : statuses) {
        System.out.println(status.getUser().getName() + ":" + status.getText());
    }

    //CODIGO BUSCAR TAGS
    Query query = new Query("Chelsea"); //Dentro del String va el tag que quieres buscar
    QueryResult result = twitter.search(query);
    for (Status status : result.getTweets()) {
        System.out.println("@" + status.getUser().getScreenName() + ":" + status.getText());
    }

}

From source file:org.tynamo.examples.federatedaccounts.pages.Index.java

License:Apache License

@RequiresPermissions("twitter")
Block onActionFromListTweets() throws TwitterException {
    OauthAccessToken accessToken = securityService.getSubject().getPrincipals()
            .oneByType(TwitterAccessToken.class);
    Twitter twitter = twitterFactory.getInstance();
    twitter.setOAuthConsumer(oauthClientId, oauthClientSecret);
    twitter.setOAuthAccessToken((AccessToken) accessToken.getCredentials());
    tweets = twitter.getHomeTimeline();
    return tweetResults.getBody();

}

From source file:org.zoneproject.extractor.twitterreader.TwitterApi.java

License:Open Source License

public static ArrayList<Item> getFluxFromTimeline(String sourceUri) {
    ArrayList<Item> result = new ArrayList<Item>();
    AccessToken userToken = TwitterApi.getAccessToken(sourceUri);
    Twitter twitter = factory.getInstance();
    twitter.setOAuthConsumer(Config.getVar("Twitter-OAuth-customer"),
            Config.getVar("Twitter-OAuth-customerKey"));
    twitter.setOAuthAccessToken(userToken);
    ResponseList<Status> status;/*from   w  w w.j a v a 2  s .  c  om*/
    try {
        status = twitter.getHomeTimeline();
        for (Status r : status) {
            result.add(TwitterApi.getItemFromStatus(r, sourceUri));
        }
    } catch (Exception ex) {
        logger.info(ex);
    }
    return result;
}

From source file:twitter.crawler.TwitterCrawler.java

public static void main(String[] args) {
    try {//www .j  a  v a 2s .c o  m
        // Authorise the library
        ConfigurationBuilder cb = new ConfigurationBuilder();
        cb.setOAuthConsumerKey("AhoydO8uSe4v8NEq7j2ISGFlq");
        cb.setOAuthConsumerSecret("ptKEYwq3G9vpFkqAhvwFLSWFcBW8U1SfqycECwK4cH6wThVba6");
        cb.setOAuthAccessToken("778240255577194496-taafqDIHebrg972oxT5kTqcNd3Uojod");
        cb.setOAuthAccessTokenSecret("DMRmeRahnLJRvCBIGQGTaTzE6Pr3PAZMgMsfWIT5ue3PD");
        Twitter twitter = new TwitterFactory(cb.build()).getInstance();
        User user = twitter.verifyCredentials(); // Get main user

        long cursor = -1;

        // Print user profile
        System.out.println("@" + user.getScreenName());
        System.out.println(user.getId());
        System.out.println(user.getProfileImageURL());
        System.out.println(user.getFriendsCount() + " friends.");
        System.out.println("-------");

        // Print Home Timeline
        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());
        }

        //Print followers
        System.out.println("-------");
        System.out.println("Showing Follwers:");

        PagableResponseList<User> followers;

        //do
        //{
        followers = twitter.getFollowersList(user.getScreenName(), cursor);

        for (User follower : followers) {
            System.out.println("@" + follower.getScreenName());
        }
        //}
        //while ((cursor = followers.getNextCursor())!=-1);

        //Print follwees

        System.out.println("-------");
        System.out.println("Showing Followees:");

        PagableResponseList<User> followees;

        do {
            followees = twitter.getFriendsList(user.getScreenName(), cursor);

            for (User followee : followees) {
                System.out.println("@" + followee.getScreenName());
            }
        } while ((cursor = followees.getNextCursor()) != -1);
    }

    catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to get timeline: " + te.getMessage());
        System.exit(-1);
    }
}

From source file:twitter4j.examples.lambda.RateLimitLambda.java

License:Apache License

public static void main(String... args) {
    Twitter twitter = TwitterFactory.getSingleton();
    twitter.onRateLimitStatus(//from   w  w  w .j  a  v a 2  s . com
            e -> System.out.println("rate limit remaining: " + e.getRateLimitStatus().getRemaining()));
    for (int i = 0; i < 20; i++) {
        try {
            System.out.println(twitter.getHomeTimeline());
        } catch (TwitterException e) {
            e.printStackTrace();
        }
    }
}