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:br.com.porcelli.hornetq.integration.twitter.stream.MessageQueuing.java

License:Apache License

public void postMessage(final DirectMessage dm, final boolean isReclaimer) throws Exception {
    final ServerMessage msg = buildMessage(data.getQueueName(), dm);
    dmCount.incrementAndGet();/*from  w  w w .  ja  va2 s  .co m*/
    totalCount.incrementAndGet();
    internalPostDM(msg, dm.getId(), isReclaimer);
}

From source file:br.com.porcelli.hornetq.integration.twitter.support.TweetMessageConverterSupport.java

License:Apache License

public static ServerMessage buildMessage(final String queueName, final DirectMessage dm) {

    final ServerMessage msg = new ServerMessageImpl(dm.getId(),
            InternalTwitterConstants.INITIAL_MESSAGE_BUFFER_SIZE);
    msg.setAddress(new SimpleString(queueName));
    msg.setDurable(true);/*from w  ww . ja v a  2s  . co m*/

    msg.putStringProperty(TwitterConstants.KEY_MSG_TYPE, MessageType.DM.toString());

    msg.putStringProperty(TwitterConstants.KEY_ID, read(dm.getId()));
    msg.putStringProperty(TwitterConstants.KEY_TEXT, read(dm.getText()));
    msg.putStringProperty(TwitterConstants.KEY_CREATED_AT, read(dm.getCreatedAt()));

    if (dm.getSender() != null) {
        buildUserData(InternalTwitterConstants.KEY_USER_SENDER_PREFIX, dm.getSender(), msg);
    }

    if (dm.getRecipient() != null) {
        buildUserData(InternalTwitterConstants.KEY_USER_RECIPIENT_PREFIX, dm.getRecipient(), msg);
    }

    msg.putStringProperty(TwitterConstants.KEY_RAW_JSON, dm.toString());

    return msg;
}

From source file:com.daiv.android.twitter.data.sq_lite.DMDataSource.java

License:Apache License

public synchronized void createDirectMessage(DirectMessage status, int account) {
    ContentValues values = new ContentValues();
    long time = status.getCreatedAt().getTime();

    values.put(DMSQLiteHelper.COLUMN_ACCOUNT, account);
    values.put(DMSQLiteHelper.COLUMN_TEXT, TweetLinkUtils.getLinksInStatus(status)[0]);
    values.put(DMSQLiteHelper.COLUMN_TWEET_ID, status.getId());
    values.put(DMSQLiteHelper.COLUMN_NAME, status.getSender().getName());
    values.put(DMSQLiteHelper.COLUMN_PRO_PIC, status.getSender().getOriginalProfileImageURL());
    values.put(DMSQLiteHelper.COLUMN_SCREEN_NAME, status.getSender().getScreenName());
    values.put(DMSQLiteHelper.COLUMN_TIME, time);
    values.put(DMSQLiteHelper.COLUMN_RETWEETER, status.getRecipientScreenName());
    values.put(DMSQLiteHelper.COLUMN_EXTRA_ONE, status.getRecipient().getOriginalProfileImageURL());
    values.put(DMSQLiteHelper.COLUMN_EXTRA_TWO, status.getRecipient().getName());
    values.put(HomeSQLiteHelper.COLUMN_PIC_URL, TweetLinkUtils.getLinksInStatus(status)[1]);

    MediaEntity[] entities = status.getMediaEntities();

    if (entities.length > 0) {
        values.put(DMSQLiteHelper.COLUMN_PIC_URL, entities[0].getMediaURL());
    }/*  w  ww . j  a  va 2s  .  com*/

    URLEntity[] urls = status.getURLEntities();
    for (URLEntity url : urls) {
        Log.v("inserting_dm", "url here: " + url.getExpandedURL());
        values.put(DMSQLiteHelper.COLUMN_URL, url.getExpandedURL());
    }

    try {
        database.insert(DMSQLiteHelper.TABLE_DM, null, values);
    } catch (Exception e) {
        open();
        database.insert(DMSQLiteHelper.TABLE_DM, null, values);
    }

}

From source file:com.dwdesign.tweetings.model.ParcelableDirectMessage.java

License:Open Source License

public ParcelableDirectMessage(final DirectMessage message, final long account_id, final boolean is_gap) {
    this.account_id = account_id;
    this.is_gap = is_gap;
    final User sender = message.getSender(), recipient = message.getRecipient();
    message_id = message.getId();
    message_timestamp = getTime(message.getCreatedAt());
    sender_id = sender != null ? sender.getId() : -1;
    recipient_id = recipient != null ? recipient.getId() : -1;
    text = message.getText();// w  w w.ja va  2 s .co  m
    sender_name = sender != null ? sender.getName() : null;
    recipient_name = recipient != null ? recipient.getName() : null;
    sender_screen_name = sender != null ? sender.getScreenName() : null;
    recipient_screen_name = recipient != null ? recipient.getScreenName() : null;
    sender_profile_image_url = sender != null ? sender.getProfileImageURL() : null;
    recipient_profile_image_url = recipient != null ? recipient.getProfileImageURL() : null;
}

From source file:com.dwdesign.tweetings.util.Utils.java

License:Open Source License

public static ContentValues makeDirectMessageContentValues(final DirectMessage message, final long account_id) {
    if (message == null || message.getId() <= 0)
        return null;
    final ContentValues values = new ContentValues();
    final User sender = message.getSender(), recipient = message.getRecipient();
    if (sender == null || recipient == null)
        return null;
    values.put(DirectMessages.ACCOUNT_ID, account_id);
    values.put(DirectMessages.MESSAGE_ID, message.getId());
    values.put(DirectMessages.MESSAGE_TIMESTAMP, message.getCreatedAt().getTime());
    values.put(DirectMessages.SENDER_ID, sender.getId());
    values.put(DirectMessages.RECIPIENT_ID, recipient.getId());
    values.put(DirectMessages.TEXT, message.getText());
    values.put(DirectMessages.SENDER_NAME, sender.getName());
    values.put(DirectMessages.SENDER_SCREEN_NAME, sender.getScreenName());
    values.put(DirectMessages.RECIPIENT_NAME, recipient.getName());
    values.put(DirectMessages.RECIPIENT_SCREEN_NAME, recipient.getScreenName());
    final URL sender_profile_image_url = sender.getProfileImageURL();
    final URL recipient_profile_image_url = recipient.getProfileImageURL();
    if (sender_profile_image_url != null) {
        values.put(DirectMessages.SENDER_PROFILE_IMAGE_URL, sender_profile_image_url.toString());
    }/*from  w w  w  .j a  va 2  s. c o m*/
    if (recipient_profile_image_url != null) {
        values.put(DirectMessages.RECIPIENT_PROFILE_IMAGE_URL, recipient_profile_image_url.toString());
    }
    return values;
}

From source file:com.ikungolf.java.javatwitter.directmessage.GetDirectMessages.java

License:Apache License

private String getLastestMessage() {
    Twitter twitter = new TwitterFactory().getInstance();
    String msg = new String();
    try {/*from   ww  w. ja va 2  s.  c  o  m*/
        Paging paging = new Paging(1);
        List<DirectMessage> messages;

        messages = twitter.getDirectMessages(paging);
        System.out.println(messages.size());
        DirectMessage dm = messages.get(0);

        System.out.println("Message: " + dm.getText());
        messageId = dm.getId();
        if (messageId != tempMsgId) {
            tempMsgId = messageId;
        }
        msg = dm.getText();

    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to get messages: " + te.getMessage());
        System.exit(-1);
    }

    return msg;
}

From source file:com.ikungolf.java.javatwitter.directmessage.GetSentDirectMessages.java

License:Apache License

/**
 * Usage: java twitter4j.examples.directmessages.GetSentDirectMessages
 *
 * @param args message//  w w w  .  ja  va2 s.  c o m
 */
public static void main(String[] args) {
    try {
        Twitter twitter = new TwitterFactory().getInstance();
        Paging page = new Paging(1);
        List<DirectMessage> directMessages;
        do {
            directMessages = twitter.getSentDirectMessages(page);
            for (DirectMessage message : directMessages) {
                System.out.println("To: @" + message.getRecipientScreenName() + " id:" + message.getId() + " - "
                        + message.getText());
            }
            page.setPage(page.getPage() + 1);
        } while (directMessages.size() > 0 && page.getPage() < 10);
        System.out.println("done.");
        System.exit(0);
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to get sent messages: " + te.getMessage());
        System.exit(-1);
    }
}

From source file:com.ikungolf.java.javatwitter.directmessage.ShowDirectMessage.java

License:Apache License

/**
 * Usage: java twitter4j.examples.directmessage.ShowDirectMessage [message id]
 *
 * @param args String[]/*from www  .  j av  a  2  s . c  om*/
 */
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: @" + message.getSenderScreenName() + " 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);
    }
}

From source file:com.marpies.ane.twitter.utils.DirectMessageUtils.java

License:Apache License

public static JSONObject getJSON(DirectMessage message) throws JSONException {
    JSONObject dmJSON = new twitter4j.JSONObject();
    dmJSON.put("id", message.getId());
    dmJSON.put("idStr", String.valueOf(message.getId()));
    dmJSON.put("text", message.getText());
    dmJSON.put("createdAt", message.getCreatedAt());
    dmJSON.put("recipient", UserUtils.getJSON(message.getRecipient()));
    dmJSON.put("sender", UserUtils.getJSON(message.getSender()));
    return dmJSON;
}

From source file:com.test.GetDirectMessages.java

License:Apache License

/**
 * Usage: java twitter4j.examples.directmessage.GetDirectMessages
 *
 * @param args String[]/*w ww . java2  s.c  om*/
 */
public static void main(String[] args) {
    //        Twitter twitter = new TwitterFactory().getInstance();
    Twitter twitter = AccountTwitterFactory.getWiseManTwitter();
    try {
        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());
            }
            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());
        System.exit(-1);
    }
}