Example usage for twitter4j DirectMessage getId

List of usage examples for twitter4j DirectMessage getId

Introduction

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

Prototype

long getId();

Source Link

Usage

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

public static void GetDirectMessage(Twitter twitter) throws ApiException, InterruptedException {
    //Twitter twitter = new TwitterFactory().getInstance();        
    try {// w  w w . ja va 2  s  .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());
    }
}

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

License:Apache License

/**
 * Usage: java twitter4j.examples.directmessage.GetDirectMessages
 *
 * @param args String[]/*from www  .j  av a  2  s.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);
    }
}

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

License:Apache License

/**
 * Usage: java twitter4j.examples.directMessage.DirectMessage [recipient screen name] [message]
 *
 * @param args String[]//from   w ww . j  ava2s .c  o  m
 */
public static void main(String[] args) {
    if (args.length < 2) {
        System.out.println(
                "Usage: java twitter4j.examples.directmessage.SendDirectMessage [recipient id] [message]");
        System.exit(-1);
    }
    Twitter twitter = new TwitterFactory().getInstance();
    try {
        DirectMessage message = twitter.sendDirectMessage(Long.parseLong(args[0]), args[1]);
        System.out.println("Direct message successfully sent to " + message.getId());
        System.out.println(" details:" + message.toString());
        System.exit(0);
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to send a direct message: " + te.getMessage());
        System.exit(-1);
    }
}

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

License:Apache License

/**
 * Usage: java twitter4j.examples.directmessage.ShowDirectMessage [message id]
 *
 * @param args String[]//from   w  ww  . j  a v a2  s  .  c  o m
 */
public static void main(String[] args) {
    if (args.length < 1) {
        System.out.println("Usage: java twitter4j.examples.directmessage.ShowDirectMessage [message id]");
        System.exit(-1);
    }
    Twitter twitter = new TwitterFactory().getInstance();
    try {
        DirectMessage message = twitter.showDirectMessage(Long.parseLong(args[0]));
        System.out.println("From: id:" + message.getId() + " - " + message.getText());
        System.exit(0);
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to get message: " + te.getMessage());
        System.exit(-1);
    }
}