Example usage for twitter4j DirectMessage getCreatedAt

List of usage examples for twitter4j DirectMessage getCreatedAt

Introduction

In this page you can find the example usage for twitter4j DirectMessage getCreatedAt.

Prototype

Date getCreatedAt();

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  .j  av a2s.  c o m
 */
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);
    }
}