Search code examples
javatwittertwitter4j

The number of re-tweets for twitter4j


How do I get the number of retweets for statuses on my timeline for Twitter4j (latest version). That is:

Status - retweet count to be outputted?


Solution

  • As far as I understand, you wanna know how many retweet counts each status has, right. There is a method that can be reached via status object to get the actual retweet count of a tweeet.

    Look at the following simple code which is printing the tweet id and retweet count for each tweet in the timeline for a given user id:

     long userId = 0000000L;
    
         try 
         {
            ResponseList<Status> statusList = twitterObj.timelines().getUserTimeline(userId);
    
            for (Status statusItem : statusList)
            {
             System.out.println("Tweet Id : " + statusItem.getId() + ", retweet count: " + statusItem.getRetweetCount());
            }               
         } 
         catch (TwitterException ex) 
         {
            // Do error handling things here
         }