Example usage for twitter4j Paging getPage

List of usage examples for twitter4j Paging getPage

Introduction

In this page you can find the example usage for twitter4j Paging getPage.

Prototype

public int getPage() 

Source Link

Usage

From source file:com.ikungolf.java.javatwitter.directmessage.GetSentDirectMessages.java

License:Apache License

/**
 * Usage: java twitter4j.examples.directmessages.GetSentDirectMessages
 *
 * @param args message//  ww  w  .j a v  a2s .  c o  m
 */
public static void main(String[] args) {
    try {
        Twitter twitter = new TwitterFactory().getInstance();
        Paging page = new Paging(1);
        List<DirectMessage> directMessages;
        do {
            directMessages = twitter.getSentDirectMessages(page);
            for (DirectMessage message : directMessages) {
                System.out.println("To: @" + message.getRecipientScreenName() + " id:" + message.getId() + " - "
                        + message.getText());
            }
            page.setPage(page.getPage() + 1);
        } while (directMessages.size() > 0 && page.getPage() < 10);
        System.out.println("done.");
        System.exit(0);
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to get sent messages: " + te.getMessage());
        System.exit(-1);
    }
}

From source file:com.test.GetDirectMessages.java

License:Apache License

/**
 * Usage: java twitter4j.examples.directmessage.GetDirectMessages
 *
 * @param args String[]//from   w  w  w .ja  v a2s . c om
 */
public static void main(String[] args) {
    //        Twitter twitter = new TwitterFactory().getInstance();
    Twitter twitter = AccountTwitterFactory.getWiseManTwitter();
    try {
        Paging paging = new Paging(1);
        List<DirectMessage> messages;
        do {
            messages = twitter.getDirectMessages(paging);
            for (DirectMessage message : messages) {
                System.out.println("From: @" + message.getSenderScreenName() + " id:" + message.getId() + " - "
                        + message.getText());
            }
            paging.setPage(paging.getPage() + 1);
        } while (messages.size() > 0 && paging.getPage() < 10);
        System.out.println("done.");
        System.exit(0);
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to get messages: " + te.getMessage());
        System.exit(-1);
    }
}

From source file:examples.GetUserListStatuses.java

License:Apache License

/**
 * Usage: java twitter4j.examples.list.GetUserListStatuses [list id]
 *
 * @param args message//from   w  w w  . ja va2  s.c  o  m
 */
public static void main(String[] args) {
    if (args.length < 1) {
        System.out.println("Usage: java twitter4j.examples.list.GetUserListStatuses [list id]");
        System.exit(-1);
    }
    try {
        Twitter twitter = new TwitterFactory().getInstance();
        Paging page = new Paging(1);
        ResponseList<Status> statuses;
        do {
            statuses = twitter.getUserListStatuses(Integer.parseInt(args[0]), page);
            for (Status status : statuses) {
                System.out.println("@" + status.getUser().getScreenName() + " - " + status.getText());
            }
            page.setPage(page.getPage() + 1);
        } while (statuses.size() > 0 && page.getPage() <= 10);
        System.out.println("done.");
        System.exit(0);
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to list statuses: " + te.getMessage());
        System.exit(-1);
    }
}

From source file:org.apache.streams.twitter.provider.TwitterTimelineProviderTask.java

License:Apache License

@Override
public void run() {

    Paging paging = new Paging(1, 200);
    List<Status> statuses = null;

    do {//from w  ww .  j  av  a  2 s  .  c om
        int keepTrying = 0;

        // keep trying to load, give it 5 attempts.
        //This value was chosen because it seemed like a reasonable number of times
        //to retry capturing a timeline given the sorts of errors that could potentially
        //occur (network timeout/interruption, faulty client, etc.)
        while (keepTrying < 5) {

            try {
                this.client = provider.getTwitterClient();

                statuses = client.getUserTimeline(id, paging);

                for (Status tStat : statuses) {
                    String json = TwitterObjectFactory.getRawJSON(tStat);

                    provider.addDatum(new StreamsDatum(json));

                }

                paging.setPage(paging.getPage() + 1);

                keepTrying = 10;
            } catch (TwitterException twitterException) {
                keepTrying += TwitterErrorHandler.handleTwitterError(client, twitterException);
            } catch (Exception e) {
                keepTrying += TwitterErrorHandler.handleTwitterError(client, e);
            }
        }
    } while (provider.shouldContinuePulling(statuses));

    LOGGER.info(id + " Thread Finished");

}

From source file:twitter.botframework.connector.TwitterBotframeworkConnector.java

public static void GetDirectMessage(Twitter twitter) throws ApiException, InterruptedException {
    //Twitter twitter = new TwitterFactory().getInstance();        
    try {//  ww w .  ja  v  a2s .  c o  m
        Paging paging = new Paging(1);
        List<DirectMessage> messages;
        do {
            messages = twitter.getDirectMessages(paging);
            for (DirectMessage message : messages) {

                System.out.println("From: @" + message.getSenderScreenName() + " id:" + message.getId() + " - "
                        + message.getText());
                user_name = user_name.concat(message.getSenderScreenName());
                user_message = message.getText();
                //send a tweet
                //Status status = twitter.updateStatus("Hola " +user_name +" Estamos atendiendo tu peticion! #Fintechando #HaciendoElParo");
                DirectLineToBot(user_name, user_message);
                SendDirectMessageAsResponse(twitter);
            }
            paging.setPage(paging.getPage() + 1);
        } while (messages.size() > 0 && paging.getPage() < 10);
        /*System.out.println("done.");
        System.exit(0);*/
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to get messages: " + te.getMessage());
    } catch (ApiException te) {
        te.printStackTrace();
        System.out.println("Failed to get messages: " + te.getMessage());
    }
}