List of usage examples for twitter4j DirectMessage getText
String getText();
From source file:org.osframework.maven.plugins.twitter.DirectMessageMojo.java
License:Apache License
protected void executeInTwitter(Twitter twitter) throws MojoExecutionException, MojoFailureException { try {//from w w w . j av a 2 s. c o m DirectMessage dm = twitter.sendDirectMessage(recipientScreenName, getMessage()); getLog().info("Sent direct message to @" + dm.getRecipientScreenName() + ": " + dm.getText()); logDirectMessage(dm); } catch (TwitterException te) { throw new MojoFailureException("Could not send direct message", te); } }
From source file:org.osframework.maven.plugins.twitter.DirectMessageMojo.java
License:Apache License
private void logDirectMessage(DirectMessage dm) { StringBuilder logMsg = new StringBuilder(formatDate(dm.getCreatedAt())).append(" ") .append(dm.getRecipientScreenName()).append(" ").append(dm.getText()); File logFile = new File(getWorkDirectory(), "dm.log"); BufferedWriter writer = null; try {/*w w w . j a va 2s. c om*/ writer = new BufferedWriter(new FileWriter(logFile, true)); writer.write(logMsg.toString()); } catch (IOException ioe) { getLog().warn("Could not write status to dm.log"); } finally { IOUtil.close(writer); } }
From source file:org.sociotech.communitymashup.source.twitter.TwitterSourceService.java
License:Open Source License
/** * Creates a content for the given message, adds it to the data set and sets * the author./*from w ww.j a v a 2s. com*/ * * @param author * Person corresponding to the twitter user which authored the * message * @param author * Person corresponding to the twitter user which received the * message * @param directMessage * The twitter status * @return The Content created from the status, null in error case. */ private Content createContentFromTwitterDirectMessage(Person author, Person receipient, DirectMessage directMessage) { if (directMessage == null) { return null; } String messageText = directMessage.getText(); if (messageText == null || messageText.isEmpty()) { return null; } String ident = directMessage.getId() + ""; if (this.getContentWithSourceIdent(ident) != null) { // message already created return null; } Content message = factory.createContent(); message.setStringValue(messageText); message.setName(createTitleFromTwitterText(messageText)); message.metaTag(TwitterTags.TWITTER); message = (Content) this.add(message, ident); if (message == null) { return null; } if (author != null) { message.setAuthor(author); } message.setCreated(directMessage.getCreatedAt()); if (receipient != null) { // set receiver as contributor message.getContributors().add(receipient); } message.metaTag(TwitterTags.DIRECT_MESSAGE); return message; }
From source file:org.tweetalib.android.model.TwitterDirectMessage.java
License:Apache License
public TwitterDirectMessage(DirectMessage message, User otherUser) { mId = message.getId();//from www.j a v a2s.c o m mText = message.getText(); mStatusFullMarkup = TwitterUtil.getStatusMarkup(mText, message.getMediaEntities(), message.getURLEntities()); mTextSpanned = URLSpanNoUnderline .stripUnderlines(Html.fromHtml(mStatusFullMarkup.replace("\n", "<br/>") + " ")); mCreatedAt = message.getCreatedAt(); mOtherUserId = otherUser.getId(); mRecipientUserId = message.getRecipientId(); mOtherUserScreenName = otherUser.getScreenName(); mOtherUserName = otherUser.getName(); mOtherUserProfileImageOriginalUrl = otherUser.getOriginalProfileImageURL(); mOtherUserProfileImageMiniUrl = otherUser.getMiniProfileImageURL(); mOtherUserProfileImageNormalUrl = otherUser.getProfileImageURL(); mOtherUserProfileImageBiggerUrl = otherUser.getBiggerProfileImageURL(); TwitterUser sender = new TwitterUser(message.getSender()); mSenderProfileImageOriginalUrl = sender.getProfileImageUrlOriginal(); mSenderProfileImageMiniUrl = sender.getProfileImageUrlMini(); mSenderProfileImageNormalUrl = sender.getProfileImageUrlNormal(); mSenderProfileImageBiggerUrl = sender.getProfileImageUrlBigger(); mMessageType = mRecipientUserId == mOtherUserId ? MessageType.SENT : MessageType.RECEIVED; }
From source file:proyectotwitter.AppTwitter.java
public void mensajeDirecto(String user, String msg) { DirectMessage message; try {//from w w w. j av a 2s. com message = twitter.sendDirectMessage("@" + user, msg); System.out.println("Sent: " + message.getText() + " to @" + message.getRecipientScreenName()); } catch (TwitterException ex) { System.out.println("Error mensaje directo"); } }
From source file:tweete.Tweete.java
License:Open Source License
public void sendMessage(String id, String msg) { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey("######################") .setOAuthConsumerSecret("######################") .setOAuthAccessToken("############################################") .setOAuthAccessTokenSecret("############################################"); TwitterFactory tf = new TwitterFactory(cb.build()); Twitter twitter = tf.getInstance();/*w w w . ja v a 2 s . c o m*/ try { DirectMessage message = null; message = twitter.sendDirectMessage(id, msg); System.out.println("Sent: " + message.getText() + " to @" + message.getRecipientScreenName()); } catch (TwitterException te) { //te.printStackTrace(); if (401 == te.getStatusCode()) { System.out.println("Unable to get the access token."); } else if (92 == te.getStatusCode()) { System.out.println("SSL is required"); } else { System.out.println("Failed to get timeline: " + te.getMessage()); System.exit(-1); } } catch (Exception e) { System.out.println("Something went wrong"); } }
From source file:twitbak.DirectMessageBak.java
License:Open Source License
/** * Adds a DirectMessage to statusArray as a JSONObject. * /* w w w. j a va 2s . c o m*/ * @param dm * @throws TwitterException * @throws JSONException */ private void dmToJson(DirectMessage dm) throws TwitterException, JSONException { JSONObject result = new JSONObject(); result.put("Created At", dm.getCreatedAt().toString()); result.put("ID", dm.getId()); result.put("Text", dm.getText()); result.put("Sender ID", dm.getSenderId()); result.put("Sender", dm.getSender().getScreenName()); result.put("Sender Name", dm.getSender().getName()); statusArray.put(result); }
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[]// w w w .j a va2s. 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.ShowDirectMessage.java
License:Apache License
/** * Usage: java twitter4j.examples.directmessage.ShowDirectMessage [message id] * * @param args String[]// ww w. j a v a2s . co 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); } }