Example usage for twitter4j DirectMessageList getNextCursor

List of usage examples for twitter4j DirectMessageList getNextCursor

Introduction

In this page you can find the example usage for twitter4j DirectMessageList getNextCursor.

Prototype

String getNextCursor();

Source Link

Usage

From source file:twitter4j.examples.directmessage.GetDirectMessages.java

License:Apache License

/**
 * Usage: java twitter4j.examples.directmessage.GetDirectMessages
 *
 * @param args String[]//from   w  w  w  . ja  v  a  2 s.  c  om
 */
public static void main(String[] args) {
    Twitter twitter = new TwitterFactory().getInstance();
    try {
        String cursor = null;
        int count = 20;
        DirectMessageList messages;
        do {
            System.out.println("* cursor:" + cursor);
            messages = cursor == null ? twitter.getDirectMessages(count)
                    : twitter.getDirectMessages(count, cursor);
            for (DirectMessage message : messages) {
                System.out.println("From: " + message.getSenderId() + " id:" + message.getId() + " ["
                        + message.getCreatedAt() + "]" + " - " + message.getText());
                System.out.println("raw[" + message + "]");
            }
            cursor = messages.getNextCursor();
        } while (messages.size() > 0 && cursor != null);
        System.out.println("done.");
        System.exit(0);
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to get messages: " + te.getMessage());
        System.exit(-1);
    }
}