List of usage examples for twitter4j Twitter getDirectMessages
DirectMessageList getDirectMessages(int count) throws TwitterException;
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.j a va2 s .co 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 w w w .j a v a 2 s.com */ 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); } }