Example usage for twitter4j Status getRetweetCount

List of usage examples for twitter4j Status getRetweetCount

Introduction

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

Prototype

int getRetweetCount();

Source Link

Document

Returns the number of times this tweet has been retweeted, or -1 when the tweet was created before this feature was enabled.

Usage

From source file:twitterswingclient.TwitterClient.java

private void updateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_updateActionPerformed
    // TODO add your handling code here:
    String consKey = "Your key";
    String consSecret = "Your secret";
    String accToken = "Your key";
    String accSecret = "Your secret";
    try {//  w  w w.j  av  a 2s. co m

        TwitterFactory twitterFactory = new TwitterFactory();

        Twitter twitter = twitterFactory.getInstance();

        twitter.setOAuthConsumer(consKey, consSecret);

        twitter.setOAuthAccessToken(new AccessToken(accToken, accSecret));

        StatusUpdate statusUpdate = new StatusUpdate(status.getText());

        statusUpdate.setMedia("Feeling great",
                new URL("http://media3.giphy.com/media/el1tH0BzEWm4w/giphy.gif").openStream());

        Status stat = twitter.updateStatus(statusUpdate);

        textArea.append("status.toString() = " + stat.toString());
        textArea.append("status.getInReplyToScreenName() = " + stat.getInReplyToScreenName());
        textArea.append("status.getSource() = " + stat.getSource());
        textArea.append("status.getText() = " + stat.getText());
        textArea.append("status.getContributors() = " + Arrays.toString(stat.getContributors()));
        textArea.append("status.getCreatedAt() = " + stat.getCreatedAt());
        textArea.append("status.getCurrentUserRetweetId() = " + stat.getCurrentUserRetweetId());
        textArea.append("status.getGeoLocation() = " + stat.getGeoLocation());
        textArea.append("status.getId() = " + stat.getId());
        textArea.append("status.getInReplyToStatusId() = " + stat.getInReplyToStatusId());
        textArea.append("status.getInReplyToUserId() = " + stat.getInReplyToUserId());
        textArea.append("status.getPlace() = " + stat.getPlace());
        textArea.append("status.getRetweetCount() = " + stat.getRetweetCount());
        textArea.append("status.getRetweetedStatus() = " + stat.getRetweetedStatus());
        textArea.append("status.getUser() = " + stat.getUser());
        textArea.append("status.getAccessLevel() = " + stat.getAccessLevel());
        textArea.append("status.getHashtagEntities() = " + Arrays.toString(stat.getHashtagEntities()));
        textArea.append("status.getMediaEntities() = " + Arrays.toString(stat.getMediaEntities()));

        if (stat.getRateLimitStatus() != null) {
            textArea.append("status.getRateLimitStatus().getLimit() = " + stat.getRateLimitStatus().getLimit());
            textArea.append(
                    "status.getRateLimitStatus().getRemaining() = " + stat.getRateLimitStatus().getRemaining());
            textArea.append("status.getRateLimitStatus().getResetTimeInSeconds() = "
                    + stat.getRateLimitStatus().getResetTimeInSeconds());
            textArea.append("status.getRateLimitStatus().getSecondsUntilReset() = "
                    + stat.getRateLimitStatus().getSecondsUntilReset());
            textArea.append("status.getRateLimitStatus().getRemainingHits() = "
                    + stat.getRateLimitStatus().getRemaining());
        }
        textArea.append("status.getURLEntities() = " + Arrays.toString(stat.getURLEntities()));
        textArea.append("status.getUserMentionEntities() = " + Arrays.toString(stat.getUserMentionEntities()));

    } catch (IOException ex) {
        textArea.append("IO Exception");
    } catch (TwitterException tw) {
        textArea.append("Twitter Exception");
    }
}

From source file:uk.co.flax.ukmp.twitter.TweetUpdateThread.java

License:Apache License

private Tweet buildTweetFromStatus(Status status) {
    String text = status.getText();

    Tweet tweet = new Tweet();
    tweet.setId("" + status.getId());
    tweet.setText(text);/*from   w w  w  . ja  v a  2 s  .  c o m*/
    tweet.setUserScreenName(status.getUser().getScreenName());
    tweet.setUserName(status.getUser().getName());
    tweet.setCreated(status.getCreatedAt());
    if (status.getPlace() != null) {
        tweet.setPlaceName(status.getPlace().getFullName());
        tweet.setCountry(status.getPlace().getCountry());
    }
    tweet.setRetweetCount(status.getRetweetCount());
    tweet.setFavouriteCount(status.getFavoriteCount());
    tweet.setParty(partyListIds.get(status.getUser().getId()));

    if (status.getUserMentionEntities() != null) {
        List<String> screenNames = new ArrayList<>(status.getUserMentionEntities().length);
        List<String> fullNames = new ArrayList<>(status.getUserMentionEntities().length);

        for (UserMentionEntity ent : status.getUserMentionEntities()) {
            screenNames.add(ent.getScreenName());
            if (StringUtils.isNotBlank(ent.getName())) {
                fullNames.add(ent.getName());
            }
        }
        tweet.setMentionScreenNames(screenNames);
        tweet.setMentionFullNames(fullNames);
    }

    if (status.getHashtagEntities().length > 0) {
        List<String> hashtags = new ArrayList<>(status.getHashtagEntities().length);
        for (HashtagEntity ht : status.getHashtagEntities()) {
            hashtags.add(ht.getText());
        }
        tweet.setHashtags(hashtags);
    }

    // Call the entity extraction service
    Map<String, List<String>> entities = entityExtraction.getEntities(text);
    if (entities != null && !entities.isEmpty()) {
        Map<String, Object> tweetEntities = new HashMap<String, Object>();
        entities.keySet().forEach(type -> tweetEntities.put(type, entities.get(type)));
        tweet.setEntities(tweetEntities);
    }

    return tweet;
}