Search in sources :

Example 1 with DirectMessageList

use of twitter4j.DirectMessageList in project twitter4j by yusuke.

the class GetDirectMessages method main.

/**
 * Usage: java twitter4j.examples.directmessage.GetDirectMessages
 *
 * @param args String[]
 */
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);
    }
}
Also used : DirectMessage(twitter4j.DirectMessage) DirectMessageList(twitter4j.DirectMessageList) Twitter(twitter4j.Twitter) TwitterFactory(twitter4j.TwitterFactory) TwitterException(twitter4j.TwitterException)

Aggregations

DirectMessage (twitter4j.DirectMessage)1 DirectMessageList (twitter4j.DirectMessageList)1 Twitter (twitter4j.Twitter)1 TwitterException (twitter4j.TwitterException)1 TwitterFactory (twitter4j.TwitterFactory)1