Example usage for twitter4j Status getId

List of usage examples for twitter4j Status getId

Introduction

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

Prototype

long getId();

Source Link

Document

Returns the id of the status

Usage

From source file:org.mariotaku.twidere.util.CacheUsersStatusesTask.java

License:Open Source License

@Override
protected Void doInBackground(final Void... args) {
    if (all_statuses == null || all_statuses.length == 0)
        return null;
    final Extractor extractor = new Extractor();
    final Set<ContentValues> cached_users_values = new HashSet<ContentValues>();
    final Set<ContentValues> cached_statuses_values = new HashSet<ContentValues>();
    final Set<ContentValues> hashtag_values = new HashSet<ContentValues>();
    final Set<Long> user_ids = new HashSet<Long>();
    final Set<Long> status_ids = new HashSet<Long>();
    final Set<String> hashtags = new HashSet<String>();
    final Set<User> users = new HashSet<User>();
    final boolean large_preview_image = Utils
            .getImagePreviewDisplayOptionInt(context) == IMAGE_PREVIEW_DISPLAY_OPTION_CODE_LARGE;

    for (final TwitterListResponse<twitter4j.Status> values : all_statuses) {
        if (values == null || values.list == null) {
            continue;
        }/*from  w  ww. j  av a  2  s.co m*/
        final List<twitter4j.Status> list = values.list;
        for (final twitter4j.Status status : list) {
            if (status == null || status.getId() <= 0) {
                continue;
            }
            status_ids.add(status.getId());
            cached_statuses_values.add(makeStatusContentValues(status, values.account_id, large_profile_image,
                    large_preview_image));
            hashtags.addAll(extractor.extractHashtags(status.getText()));
            final User user = status.getUser();
            if (user != null && user.getId() > 0) {
                users.add(user);
            }
        }
    }

    bulkDelete(resolver, CachedStatuses.CONTENT_URI, CachedStatuses.STATUS_ID, status_ids, null, false);
    bulkInsert(resolver, CachedStatuses.CONTENT_URI, cached_statuses_values);

    for (final String hashtag : hashtags) {
        final ContentValues hashtag_value = new ContentValues();
        hashtag_value.put(CachedHashtags.NAME, hashtag);
        hashtag_values.add(hashtag_value);
    }
    bulkDelete(resolver, CachedHashtags.CONTENT_URI, CachedHashtags.NAME, hashtags, null, true);
    bulkInsert(resolver, CachedHashtags.CONTENT_URI, hashtag_values);

    for (final User user : users) {
        user_ids.add(user.getId());
        cached_users_values.add(makeCachedUserContentValues(user, large_profile_image));
    }
    bulkDelete(resolver, CachedUsers.CONTENT_URI, CachedUsers.USER_ID, user_ids, null, false);
    bulkInsert(resolver, CachedUsers.CONTENT_URI, cached_users_values);
    return null;
}

From source file:org.mariotaku.twidere.util.ContentValuesCreator.java

License:Open Source License

@NonNull
public static ContentValues createStatus(final Status orig, final long accountId) {
    if (orig == null)
        throw new NullPointerException();
    final ContentValues values = new ContentValues();
    values.put(Statuses.ACCOUNT_ID, accountId);
    values.put(Statuses.STATUS_ID, orig.getId());
    values.put(Statuses.STATUS_TIMESTAMP, orig.getCreatedAt().getTime());
    final Status status;
    if (orig.isRetweet()) {
        final Status retweetedStatus = orig.getRetweetedStatus();
        final User retweetUser = orig.getUser();
        final long retweetedById = retweetUser.getId();
        values.put(Statuses.RETWEET_ID, retweetedStatus.getId());
        values.put(Statuses.RETWEET_TIMESTAMP, retweetedStatus.getCreatedAt().getTime());
        values.put(Statuses.RETWEETED_BY_USER_ID, retweetedById);
        values.put(Statuses.RETWEETED_BY_USER_NAME, retweetUser.getName());
        values.put(Statuses.RETWEETED_BY_USER_SCREEN_NAME, retweetUser.getScreenName());
        values.put(Statuses.RETWEETED_BY_USER_PROFILE_IMAGE, (retweetUser.getProfileImageUrlHttps()));
        values.put(Statuses.IS_RETWEET, true);
        if (retweetedById == accountId) {
            values.put(Statuses.MY_RETWEET_ID, orig.getId());
        } else {// w w  w .j ava 2s .com
            values.put(Statuses.MY_RETWEET_ID, orig.getCurrentUserRetweet());
        }
        status = retweetedStatus;
    } else if (orig.isQuote()) {
        final Status quotedStatus = orig.getQuotedStatus();
        final User quoteUser = orig.getUser();
        final long quotedById = quoteUser.getId();
        values.put(Statuses.QUOTE_ID, quotedStatus.getId());
        final String textHtml = TwitterContentUtils.formatStatusText(orig);
        values.put(Statuses.QUOTE_TEXT_HTML, textHtml);
        values.put(Statuses.QUOTE_TEXT_PLAIN, orig.getText());
        values.put(Statuses.QUOTE_TEXT_UNESCAPED, toPlainText(textHtml));
        values.put(Statuses.QUOTE_TIMESTAMP, orig.getCreatedAt().getTime());
        values.put(Statuses.QUOTE_SOURCE, orig.getSource());
        final ParcelableMedia[] quoteMedia = ParcelableMedia.fromStatus(orig);
        if (quoteMedia != null && quoteMedia.length > 0) {
            try {
                values.put(Statuses.QUOTE_MEDIA_JSON,
                        LoganSquare.serialize(Arrays.asList(quoteMedia), ParcelableMedia.class));
            } catch (IOException ignored) {
            }
        }
        values.put(Statuses.QUOTED_BY_USER_ID, quotedById);
        values.put(Statuses.QUOTED_BY_USER_NAME, quoteUser.getName());
        values.put(Statuses.QUOTED_BY_USER_SCREEN_NAME, quoteUser.getScreenName());
        values.put(Statuses.QUOTED_BY_USER_PROFILE_IMAGE, quoteUser.getProfileImageUrlHttps());
        values.put(Statuses.QUOTED_BY_USER_IS_VERIFIED, quoteUser.isVerified());
        values.put(Statuses.QUOTED_BY_USER_IS_PROTECTED, quoteUser.isProtected());
        values.put(Statuses.IS_QUOTE, true);
        status = quotedStatus;
    } else {
        values.put(Statuses.MY_RETWEET_ID, orig.getCurrentUserRetweet());
        status = orig;
    }
    if (orig.isRetweet()) {
        values.put(Statuses.IN_REPLY_TO_STATUS_ID, status.getInReplyToStatusId());
        values.put(Statuses.IN_REPLY_TO_USER_ID, status.getInReplyToUserId());
        values.put(Statuses.IN_REPLY_TO_USER_NAME, TwitterContentUtils.getInReplyToName(status));
        values.put(Statuses.IN_REPLY_TO_USER_SCREEN_NAME, status.getInReplyToScreenName());
    } else {
        values.put(Statuses.IN_REPLY_TO_STATUS_ID, orig.getInReplyToStatusId());
        values.put(Statuses.IN_REPLY_TO_USER_ID, orig.getInReplyToUserId());
        values.put(Statuses.IN_REPLY_TO_USER_NAME, TwitterContentUtils.getInReplyToName(orig));
        values.put(Statuses.IN_REPLY_TO_USER_SCREEN_NAME, orig.getInReplyToScreenName());
    }
    final User user = status.getUser();
    final long userId = user.getId();
    final String profileImageUrl = (user.getProfileImageUrlHttps());
    final String name = user.getName(), screenName = user.getScreenName();
    values.put(Statuses.USER_ID, userId);
    values.put(Statuses.USER_NAME, name);
    values.put(Statuses.USER_SCREEN_NAME, screenName);
    values.put(Statuses.IS_PROTECTED, user.isProtected());
    values.put(Statuses.IS_VERIFIED, user.isVerified());
    values.put(Statuses.USER_PROFILE_IMAGE_URL, profileImageUrl);
    values.put(CachedUsers.IS_FOLLOWING, user.isFollowing());
    final String textHtml = TwitterContentUtils.formatStatusText(status);
    values.put(Statuses.TEXT_HTML, textHtml);
    values.put(Statuses.TEXT_PLAIN, status.getText());
    values.put(Statuses.TEXT_UNESCAPED, toPlainText(textHtml));
    values.put(Statuses.RETWEET_COUNT, status.getRetweetCount());
    values.put(Statuses.REPLY_COUNT, status.getReplyCount());
    values.put(Statuses.FAVORITE_COUNT, status.getFavoriteCount());
    values.put(Statuses.DESCENDENT_REPLY_COUNT, status.getDescendentReplyCount());
    values.put(Statuses.SOURCE, status.getSource());
    values.put(Statuses.IS_POSSIBLY_SENSITIVE, status.isPossiblySensitive());
    final GeoLocation location = status.getGeoLocation();
    if (location != null) {
        values.put(Statuses.LOCATION,
                ParcelableLocation.toString(location.getLatitude(), location.getLongitude()));
    }
    final Place place = status.getPlace();
    if (place != null) {
        values.put(Statuses.PLACE_FULL_NAME, place.getFullName());
    }
    values.put(Statuses.IS_FAVORITE, status.isFavorited());
    final ParcelableMedia[] media = ParcelableMedia.fromStatus(status);
    if (media != null && media.length > 0) {
        try {
            values.put(Statuses.MEDIA_JSON, LoganSquare.serialize(Arrays.asList(media), ParcelableMedia.class));
        } catch (IOException ignored) {
        }
    }
    final ParcelableUserMention[] mentions = ParcelableUserMention.fromStatus(status);
    if (mentions != null && mentions.length > 0) {
        try {
            values.put(Statuses.MENTIONS_JSON,
                    LoganSquare.serialize(Arrays.asList(mentions), ParcelableUserMention.class));
        } catch (IOException ignored) {
        }
    }
    final ParcelableCardEntity card = ParcelableCardEntity.fromCardEntity(status.getCard(), accountId);
    if (card != null) {
        try {
            values.put(Statuses.CARD, LoganSquare.serialize(card));
            values.put(Statuses.CARD_NAME, card.name);
        } catch (IOException ignored) {
        }
    }
    return values;
}

From source file:org.mule.twitter.automation.TwitterTestUtils.java

License:Open Source License

public static boolean isStatusIdOnTimeline(ResponseList<Status> statusList, long statusId) {

    Status status;
    boolean found = false;

    Iterator<Status> iter = statusList.iterator();
    while (iter.hasNext() && found == false) {
        status = iter.next();/*from   ww w.  jav a 2s . c  o m*/
        if (status.getId() == statusId) {
            found = true;
        }
    }
    return found;
}

From source file:org.mule.twitter.automation.TwitterTestUtils.java

License:Open Source License

public static String getStatusTextOnTimeline(ResponseList<Status> statusList, long statusId) {

    Status status;
    boolean found = false;

    Iterator<Status> iter = statusList.iterator();
    while (iter.hasNext() && found == false) {
        status = iter.next();/*from   www  .  j  a v a  2s  .  c o  m*/
        if (status.getId() == statusId) {
            return status.getText();
        }
    }
    return null;
}

From source file:org.mule.twitter.automation.TwitterTestUtils.java

License:Open Source License

public static String getStatusTextOnResponseList(ResponseList<Status> statusList, long statusId) {

    Status status;
    String statusText = "";
    boolean found = false;

    Iterator<Status> iter = statusList.iterator();
    while (iter.hasNext() && found == false) {
        status = iter.next();//from  w ww. ja va 2s  . co m
        if (status.getId() == statusId) {
            statusText = status.getText();
            found = true;
        }
    }
    return statusText;
}

From source file:org.mule.twitter.automation.TwitterTestUtils.java

License:Open Source License

public static long getIdForStatusTextOnResponseList(ResponseList<Status> statusList, String statusText) {

    Status status;
    long statusId = 0;
    boolean found = false;

    Iterator<Status> iter = statusList.iterator();
    while (iter.hasNext() && found == false) {
        status = iter.next();/*from   w w  w. ja v a2s .c  o  m*/
        if (status.getText().contains(statusText)) {
            statusId = status.getId();
            found = true;
        }
    }
    return statusId;
}

From source file:org.mule.twitter.TwitterConnector.java

License:Open Source License

/**
 * Updates the authenticating user's status. A status update with text identical
 * to the authenticating user's text identical to the authenticating user's
 * current status will be ignored to prevent duplicates. <br>
 * This method calls http://api.twitter.com/1.1/statuses/update
 * <p/>//from  w w w  . jav  a 2  s . co  m
 * {@sample.xml ../../../doc/twitter-connector.xml.sample twitter:updateStatus}
 *
 * @param status    the text of your status update
 * @param inReplyTo The ID of an existing status that the update is in reply to.
 * @param latitude  The latitude of the location this tweet refers to. This parameter will be ignored unless it is
 *                  inside the range -90.0 to +90.0 (North is positive) inclusive.
 * @param longitude he longitude of the location this tweet refers to. The valid ranges for longitude is -180.0 to
 *                  +180.0 (East is positive) inclusive. This parameter will be ignored if outside that range or if there not a
 *                  corresponding lat parameter.
 * @return the latest {@link Status}
 * @throws TwitterException when Twitter service or network is unavailable
 * @see <a href="http://dev.twitter.com/doc/post/statuses/update">POST
 *      statuses/update | dev.twitter.com</a>
 */
@Processor
public Status updateStatus(String status, @Default(value = "-1") @Optional long inReplyTo,
        @Placement(group = "Coordinates") @Optional Double latitude,
        @Placement(group = "Coordinates") @Optional Double longitude) throws TwitterException {
    StatusUpdate update = new StatusUpdate(status);
    if (inReplyTo > 0) {
        update.setInReplyToStatusId(inReplyTo);
    }
    if (latitude != null && longitude != null) {
        update.setLocation(new GeoLocation(latitude, longitude));
    }
    Status response = twitter.updateStatus(update);

    //Twitter4j doesn't throw exception when json reponse has 'error: Could not authenticate with OAuth'
    if (response.getId() == -1) {
        throw new TwitterException("Could not authenticate with OAuth\n");
    }

    return response;
}

From source file:org.n52.twitter.dao.TwitterAbstractDAO.java

License:Open Source License

/**
 * @throws TwitterException - when Twitter service or network is unavailable
 * @throws DecodingException /*from ww  w . j  a v  a2  s . c om*/
 */
protected Collection<TwitterMessage> executeApiRequest(Query query) throws TwitterException, DecodingException {
    LinkedList<TwitterMessage> tweets = new LinkedList<>();
    long lastID = Long.MAX_VALUE;
    int requestCount = 0;

    query.setResultType(ResultType.mixed);

    while (tweets.size() < MAX_TWEETS_TO_HARVEST) {
        if (MAX_TWEETS_TO_HARVEST - tweets.size() > TWEETS_TO_LOAD_PER_API_REQUEST) {
            query.setCount(TWEETS_TO_LOAD_PER_API_REQUEST);
        } else {
            query.setCount(MAX_TWEETS_TO_HARVEST - tweets.size());
        }
        try {
            QueryResult result = twitter.search(query);
            requestCount++;
            if (result.getTweets().isEmpty()) {
                break;
            }
            for (Status tweet : result.getTweets()) {
                TwitterMessage message = TwitterMessage.create(tweet);
                if (message != null) {
                    tweets.add(message);
                }
                if (tweet.getId() < lastID) {
                    lastID = tweet.getId();
                }
            }
            query.setMaxId(lastID - 1);
            LOGGER.debug("Progress: " + tweets.size() + "/" + MAX_TWEETS_TO_HARVEST + "(Requests: "
                    + requestCount + ")");
        } catch (TwitterException e) {
            LOGGER.error(e.getErrorMessage(), e);
            throw e;
        }
    }

    LOGGER.debug("Result count :" + tweets.size());

    return tweets;
}

From source file:org.n52.twitter.model.TwitterMessage.java

License:Open Source License

public static TwitterMessage create(Status tweet) {
    if (isGeolocated(tweet)) {
        TwitterMessage result = new TwitterMessage();
        result.id = Long.toString(tweet.getId());
        result.procedure = new Procedure(tweet.getUser().getScreenName(),
                String.format(USER_URL, tweet.getUser().getScreenName()));
        result.location = new TwitterLocation(tweet.getGeoLocation(), tweet.getPlace());
        result.createdTime = new DateTime(tweet.getCreatedAt(), DateTimeZone.UTC);
        result.link = String.format(TWEET_URL, tweet.getUser().getScreenName(), Long.toString(tweet.getId()));
        result.message = tweet.getText();
        return result;
    }/*from w  w  w. ja v a  2  s  .  co m*/
    return null;
}

From source file:org.nsoft.openbus.model.Mensagem.java

License:Open Source License

public static Mensagem creteFromTwitterStatus(Status s) {
    try {/*from  w  ww .  j  a v a 2  s . co m*/
        Mensagem mensagem = new Mensagem();

        String text = s.getText();

        for (HashtagEntity h : s.getHashtagEntities()) {

            String subText = "<a href=\"twitter_search://do_search?search=" + h.getText() + "\">#" + h.getText()
                    + "</a>";
            text = text.replace("#" + h.getText(), subText);

        }

        for (UserMentionEntity u : s.getUserMentionEntities()) {

            String subText = "<a href=\"twitter_search_user://find_user?username=" + u.getScreenName() + "\">@"
                    + u.getScreenName() + "</a>";
            text = text.replace("@" + u.getScreenName(), subText);

        }

        mensagem.setAction(OpenTwitterStatusAction.getInstance());
        mensagem.addtions = createAddtions(s);
        mensagem.addtions.put("htmlText", text);
        mensagem.idMensagem = Long.toString(s.getId());
        mensagem.nome_usuario = s.getUser().getName();
        mensagem.mensagem = s.getText();
        mensagem.imagePath = new URL(s.getUser().getOriginalProfileImageURL());
        mensagem.data = s.getCreatedAt();
        mensagem.idUser = s.getUser().getId();
        mensagem.tipo = TIPO_STATUS;

        return mensagem;
    } catch (JSONException e) {
        return null;
    } catch (MalformedURLException e) {
        return null;
    }
}