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:com.raythos.sentilexo.twitter.domain.QueryResultItemMapper.java

License:Apache License

public static TwitterQueryResultItemAvro mapItem(String queryOwner, String queryName, String queryString,
        Status status) {
    TwitterQueryResultItemAvro result = new TwitterQueryResultItemAvro();

    if (queryName != null)
        queryName = queryName.toLowerCase();
    if (queryOwner != null)
        queryOwner = queryOwner.toLowerCase();

    result.setQueryName(queryName);/*from   ww w.j  av  a 2  s. c  om*/
    result.setQueryOwner(queryOwner);
    result.setQuery(queryString);
    result.setStatusId(status.getId());
    result.setText(status.getText());

    result.setRelevantQueryTerms(TwitterUtils.relevantQueryTermsFromStatus(queryString, status));
    result.setLang(status.getLang());

    result.setCreatedAt(status.getCreatedAt().getTime());

    User user = status.getUser();
    result.setUserId(user.getId());
    result.setScreenName(user.getScreenName());
    result.setUserLocation(user.getLocation());
    result.setUserName(user.getName());
    result.setUserDescription(user.getDescription());
    result.setUserIsProtected(user.isProtected());
    result.setUserFollowersCount(user.getFollowersCount());
    result.setUserCreatedAt(user.getCreatedAt().getTime());
    result.setUserCreatedAtAsString(DateTimeUtils.getDateAsText(user.getCreatedAt()));
    result.setCreatedAtAsString(DateTimeUtils.getDateAsText(status.getCreatedAt()));
    result.setUserFriendsCount(user.getFriendsCount());
    result.setUserListedCount(user.getListedCount());
    result.setUserStatusesCount(user.getStatusesCount());
    result.setUserFavoritesCount(user.getFavouritesCount());

    result.setCurrentUserRetweetId(status.getCurrentUserRetweetId());

    result.setInReplyToScreenName(status.getInReplyToScreenName());
    result.setInReplyToStatusId(status.getInReplyToStatusId());
    result.setInReplyToUserId(status.getInReplyToUserId());

    if (status.getGeoLocation() != null) {
        result.setLatitude(status.getGeoLocation().getLatitude());
        result.setLongitude(status.getGeoLocation().getLongitude());
    }

    result.setSource(status.getSource());
    result.setTrucated(status.isTruncated());
    result.setPossiblySensitive(status.isPossiblySensitive());

    result.setRetweet(status.getRetweetedStatus() != null);
    if (result.getRetweet()) {
        result.setRetweetStatusId(status.getRetweetedStatus().getId());
        result.setRetweetedText(status.getRetweetedStatus().getText());
    }
    result.setRetweeted(status.isRetweeted());
    result.setRetweetCount(status.getRetweetCount());
    result.setRetweetedByMe(status.isRetweetedByMe());

    result.setFavoriteCount(status.getFavoriteCount());
    result.setFavourited(status.isFavorited());

    if (status.getPlace() != null) {
        result.setPlace(status.getPlace().getFullName());
    }

    Scopes scopesObj = status.getScopes();
    if (scopesObj != null) {
        List scopes = Arrays.asList(scopesObj.getPlaceIds());
        result.setScopes(scopes);
    }
    return result;
}

From source file:com.rhymestore.twitter.stream.GetMentionsListener.java

License:Open Source License

@Override
public void onStatus(final Status status) {
    UserMentionEntity[] mentions = status.getUserMentionEntities();
    if (mentions != null) {
        for (UserMentionEntity mention : mentions) {
            try {
                // Check if there is any mention to us
                if (isCurrentUser(twitter, mention.getScreenName())) {
                    // Only reply if it is a valid mention
                    if (isValidMention(status) && !isCurrentUser(twitter, status.getUser().getScreenName())) {
                        LOGGER.debug("Processing tweet {} from {}", status.getId(),
                                status.getUser().getScreenName());

                        ReplyCommand reply = new ReplyCommand(twitter, wordParser, rhymeStore, status);
                        reply.execute();
                    } else {
                        LOGGER.debug("Ignoring mention: {}", status.getText());
                    }/* w  w  w .ja  va2 s .c o  m*/

                    // Do not process the same tweet more than once
                    break;
                }
            } catch (TwitterException ex) {
                LOGGER.error("Could not process status: {}", status.getText());
            }
        }
    }
}

From source file:com.rowland.hashtrace.utility.Utility.java

License:Apache License

public static Tweet createTweet(Status status) {
    User user = status.getUser();/*  ww w . ja  va  2s  .  c  o  m*/

    long tweet_id = status.getId();

    String tweet_text = status.getText();

    Date tweet_text_date = status.getCreatedAt();

    int tweet_retweet_count = status.getRetweetCount();

    int tweet_favourite_count = status.getFavoriteCount();

    int tweet_mentions_count = status.getUserMentionEntities().length;

    String user_name = user.getScreenName();

    String user_image_url = user.getBiggerProfileImageURL();

    String user_cover_url = user.getProfileBackgroundImageURL();

    String user_location = user.getLocation();

    String user_description = user.getDescription();

    Tweet tweet = new Tweet(tweet_id, tweet_text, tweet_text_date, tweet_retweet_count, tweet_favourite_count,
            tweet_mentions_count, user_name, user_image_url, user_location, user_description, user_cover_url);

    return tweet;
}

From source file:com.sampath.kinesis.CassandraStoreProcessor.java

License:Open Source License

/** Process records performing retries as needed. Skip "poison pill" records.
 * @param records//from www  . j  a v a2  s.c o m
 */
private void processRecordsWithRetries(List<Record> records) {
    for (Record record : records) {
        boolean processedSuccessfully = false;
        String data = null;
        for (int i = 0; i < NUM_RETRIES; i++) {
            try {
                // For this app, we interpret the payload as UTF-8 chars.
                data = decoder.decode(record.getData()).toString();
                LOG.debug(record.getSequenceNumber() + ", " + record.getPartitionKey() + ", " + data);
                try {
                    Status tweet = DataObjectFactory.createStatus(data);
                    client.insert("tweets", "tweet_id", "" + tweet.getId(), "tweet", data);
                } catch (Exception e) {
                }
                //
                // Logic to process record goes here.
                //
                processedSuccessfully = true;
                break;
            } catch (CharacterCodingException e) {
                LOG.error("Malformed data: " + data, e);
                break;
            } catch (Throwable t) {
                LOG.warn("Caught throwable while processing record " + record, t);
            }

            // backoff if we encounter an exception.
            try {
                Thread.sleep(BACKOFF_TIME_IN_MILLIS);
            } catch (InterruptedException e) {
                LOG.debug("Interrupted sleep", e);
            }
        }

        if (!processedSuccessfully) {
            LOG.error("Couldn't process record " + record + ". Skipping the record.");
        }
    }
}

From source file:com.tuncaysenturk.jira.plugins.jtp.twitter.JiraTwitterUserStreamListener.java

@Override
public void onStatus(Status status) {
    PropertySet propSet = ComponentManager.getComponent(PropertiesManager.class).getPropertySet();
    if (!licenseValidator.isValid()) {
        logger.error(JTPConstants.LOG_PRE + "License problem, see configuration page");
        ExceptionMessagesUtil.addLicenseExceptionMessage();
    } else {/*from   www  . ja va  2s .c  om*/
        logger.info(JTPConstants.LOG_PRE + "onStatus @" + status.getUser().getScreenName() + " - "
                + status.getText());

        ExceptionMessagesUtil.cleanAllExceptionMessages();

        checkAndSetScreenName();
        if (StringUtils.isEmpty(screenName)) {
            ExceptionMessagesUtil
                    .addExceptionMessage("No Screen name found, please authorize Twitter account!");
            return;
        }
        if (status.getUser().getScreenName().equals(screenName)) {
            // tweet is mine, do not respond it
            return;
        }
        String text = StringUtils.trim(status.getText().replace("@" + screenName, ""));

        if (propSet.getBoolean("onlyFollowers") && !isFollower(status.getUser().getId())) {
            logger.warn(JTPConstants.LOG_PRE + status.getUser().getScreenName()
                    + " is not a follower but mentioned to create issue");
            return;
        }
        String userName = propSet.getString("userId");
        String issueTypeId = propSet.getString("issueTypeId");
        if (status.getInReplyToStatusId() == -1) {
            // -1 means that this is not reply, it's main tweet
            String projectId = propSet.getString("projectId");
            issueService.createIssue(userName, status.getUser().getScreenName(), text,
                    Long.parseLong(projectId), issueTypeId);
        } else if (status.getInReplyToStatusId() > 0) {
            // this is a reply tweet, so add comment to main issue
            long statusId = status.getInReplyToStatusId();
            TweetIssueRel rel = tweetIssueRelService.findTweetIssueRelByTweetStatusId(statusId);
            Long issueId = null;
            if (null != rel)
                issueId = rel.getIssueId();
            if (null != issueId) {
                issueService.addComment(userName, status.getUser().getScreenName(), issueId, text);
                // assosiate this tweet with issue,
                // so that replies to this tweet will be comments to the issue
                tweetIssueRelService.persistRelation(issueId, status.getId());
            }
        }
    }
}

From source file:com.TweetExtractor.java

/**
 * *// w  w  w  .j  a  va 2 s.  co m
 *
 */
public ArrayList<Tweet> retrieveTweets(String searchWord) {

    Paging paging;

    // set the lowest value of the tweet ID initially to one less than Long.MAX_VALUE
    long min_id = Long.MAX_VALUE - 1;
    int count = 0;
    int index = 0;
    boolean maxValueReached = false;
    userToSearch = searchWord;

    while (true) {
        try {

            //count = tweetList.size();
            // paging tweets at a rate of 100 per page
            paging = new Paging(1, 100);

            // if this is not the first iteration set the new min_id value for the page
            if (count != 0) {

                paging.setMaxId(min_id - 1);
            }

            // get a page of the tweet timeline with tweets with ids less than the min_id value
            List<Status> tweetTempList = twitterApp.getUserTimeline(userToSearch, paging);

            // iterate the results and add to tweetList
            for (Status s : tweetTempList) {
                if (count == maxTweets) {
                    maxValueReached = true;
                    break;
                }
                count++;
                Tweet tweet = new Tweet(s.getId(), s.getCreatedAt(), s.getText());
                tweetList.add(tweet);

                // set the value for the min value for the next iteration
                if (s.getId() < min_id) {
                    min_id = s.getId();
                }
            }

            // if the results for this iteration is zero, means we have reached the API limit or we have extracted the maximum
            // possible, so break
            if (tweetTempList.size() == 0 || maxValueReached) {
                return tweetList;
                // break;
            }

        } catch (TwitterException e) {
            e.printStackTrace();
            break;
        } catch (Exception e) {
            e.printStackTrace();
            break;
        }
    }
    return tweetList;

}

From source file:com.tweetmyhome.TweetMyHome.java

private void sendT(String text) {
    try {//from w  w w .  j  a  v  a 2 s .c o  m
        long superUserId = db.getSuperAdminId();
        Status updateStatus = tw.updateStatus(text);
        SimpleMention sm = new SimpleMention(this, updateStatus.getId(), superUserId, null, text,
                Calendar.getInstance().getTimeInMillis());
        db.add(sm);
        tweetCount.incementCount();
    } catch (TwitterException ex) {
        error(ex.toString(), ex);
    }
}

From source file:com.tweetmyhome.TweetMyHome.java

/**
 * funcion se dispara cuando te mencionan sin ser amigo
 * funcion se dipara cuando alguien que sigues habla cualquier wea
 * funcion se dispara cuando la propia casa twittea
 * @param status //from  ww w  .  j a  v  a 2  s.co m
 */
@Override
public void onStatus(Status status) {
    User user = status.getUser();
    debug("onStatus @" + status.getUser().getScreenName() + " : " + status.getText());
    if (TwitterUserUtil.equals(status.getUser().getScreenName(), p.getValueByKey(Key.twitterSuperUser))) {
        debug("Own tweet detected... EXITING function");
        return;
    }
    TweetStringAnalizer tsa;
    try {
        tsa = new TweetStringAnalizer(status.getText(), tweetDictionary);
    } catch (TweetStringException ex) {
        error(ex.toString(), ex);
        return;
    }
    Map<Integer, String> mencionedUsers = tsa.getMencionedUsers();
    if (mencionedUsers != null) {
        boolean isHomeMencioned = false;
        for (Map.Entry<Integer, String> entry : mencionedUsers.entrySet()) {
            if (TwitterUserUtil.equals(entry.getValue(), p.getValueByKey(Key.twitterSuperUser))) {
                isHomeMencioned = true;
                break;
            }
        }
        if (isHomeMencioned) {
            if (!tsa.isErrorFounded()) {
                try {
                    db.add(new SimpleMention(this, status.getId(), status.getUser().getId(), null,
                            status.getText(), Calendar.getInstance().getTimeInMillis()));
                    analyzeAndRespond(user, tsa, false);
                } catch (TwitterException | TweetMyHomeException ex) {
                    error(ex.toString(), ex);
                }
            } else {
                error(tsa.getErrorString().toString());
            }
        } else {
            debug("Users were mencioned, but not this home...");
        }
    } else {
        debug("None user Mencioned...");
    }
}

From source file:com.twitstreet.twitter.AdsListenerMgrImpl.java

License:Open Source License

@Override
public void start() {
    TwitterStream twitterStream = new TwitterStreamFactory().getInstance();
    Announcer announcer = announcerMgr.randomAnnouncerData();
    twitterStream.setOAuthConsumer(announcer.getConsumerKey(), announcer.getConsumerSecret());
    twitterStream/*from  w ww . j  a v a2s  . c  o  m*/
            .setOAuthAccessToken(new AccessToken(announcer.getAccessToken(), announcer.getAccessTokenSecret()));
    twitterStream.addListener(new StatusListener() {

        @Override
        public void onException(Exception arg0) {

        }

        @Override
        public void onTrackLimitationNotice(int arg0) {

        }

        @Override
        public void onStatus(Status status) {
            HashtagEntity[] hashtagEntities = status.getHashtagEntities();
            String screenName = status.getUser().getScreenName();
            User user = status.getUser();
            if (user != null && (System.currentTimeMillis() - lastMessage > TEN_MIN)) {
                lastMessage = System.currentTimeMillis();

                int action = (int) (ACTION_TYPES * Math.random());
                switch (action) {
                case REGULAR_TWEET:
                    LocalizationUtil lutil = LocalizationUtil.getInstance();
                    int sentenceSize = Integer
                            .parseInt(lutil.get("announcer.sentence.size", LocalizationUtil.DEFAULT_LANGUAGE));
                    int random = (int) (Math.random() * sentenceSize);
                    String rndMessage = lutil.get("announcer.sentence." + random,
                            LocalizationUtil.DEFAULT_LANGUAGE);
                    announcerMgr.announceFromRandomAnnouncer(rndMessage);
                    break;
                case RETWEEET:
                    announcerMgr.retweet(status.getId());
                    break;
                case FAVOURITE:
                    announcerMgr.favourite(status.getId());
                    break;
                default:
                    String message = constructAdsMessage(screenName, hashtagEntities,
                            status.getUser().getLang());
                    announcerMgr.reply(message, status.getId());
                    break;
                }

            }
        }

        @Override
        public void onScrubGeo(long arg0, long arg1) {

        }

        @Override
        public void onDeletionNotice(StatusDeletionNotice arg0) {
        }
    });

    FilterQuery filterQuery = new FilterQuery();
    filterQuery.count(0);
    filterQuery.track(FILTER_TERMS);
    twitterStream.filter(filterQuery);
}

From source file:com.twitt4droid.data.dao.impl.sqlite.ListSQLiteDAO.java

License:Apache License

/** {@inheritDoc} */
@Override/*w ww .  j  a v  a 2 s  .  co m*/
public void save(final List<Status> statuses, final Long listId) {
    getSQLiteTemplate().batchExecute(getSqlString(R.string.twitt4droid_insert_list_status_sql),
            new SQLiteTemplate.BatchSQLiteStatementBinder() {

                @Override
                public int getBatchSize() {
                    return statuses.size();
                }

                @Override
                public void bindValues(SQLiteStatement statement, int i) {
                    Status status = statuses.get(i);
                    int index = 0;
                    statement.bindLong(++index, status.getId());
                    statement.bindLong(++index, listId);
                    statement.bindString(++index, status.getText());
                    statement.bindString(++index, status.getUser().getScreenName());
                    statement.bindString(++index, status.getUser().getName());
                    statement.bindLong(++index, status.getCreatedAt().getTime());
                    statement.bindString(++index, status.getUser().getProfileImageURL());
                }
            });
}