1

The title is confusing, I know, but I do not know how else to phrase this question.

Using twitter4j, I am able to get tweets and the list of users who have retweeted that tweet, like this

However, if the tweet is actually a retweet then I am not able to get the list of retweeters. Example

This is the code I am using to get the list of retweeters:

if(tweet.getId() > 0 && tweet.getRetweetCount() > 0) {
    try {
        List<Status> statuses = twitter.getRetweets(tweet.getId());
        for (Status status : statuses) {
            System.out.println("\n" + "\t" + "Retweeter ID:" + status.getUser().getId() + "\n" +  "\t" + "Retweeter Name:" + status.getUser().getScreenName()); 
        }
    } catch (TwitterException e) {
        //twitter.getRetweeterIds(tweet.getId(), 2, -1);
        e.printStackTrace();
    }
}

How do I get the retweeters of a retweet?

SilverNak
  • 3,283
  • 4
  • 28
  • 44
R. Haroon
  • 103
  • 1
  • 13
  • Do you have the twitter API for expected responses? That's the reference you'd want to follow – MrJLP Apr 19 '17 at 06:23
  • @MrJLP 4 I checked the twitter api console. It doesn't give me any result. I am making this call to the twitter api: GET https://api.twitter.com/1.1/statuses/retweets/854183122266497024.json – R. Haroon Apr 19 '17 at 10:37
  • 1
    You're retrieving it as a retweet? How about get the original tweet. I'd imagine that would have it. You need to understand how the API works – MrJLP Apr 19 '17 at 10:56
  • @MrJLP Thanks it worked! I got the original tweet and then found out the user id and screen name of the retweeters. – R. Haroon Apr 19 '17 at 11:50
  • Great. I posted an answer for posterity – MrJLP Apr 19 '17 at 18:33

1 Answers1

1

Twitter4J is a Java client library that interfaces with the Twitter REST API. To understand the right call to use it's best to understand the underlying REST API.

Looking at the Twitter Rest API we can see an API that returns a list of users who have retweeted a particular tweet, GET statuses/retweeters/ids.

In your code the Twitter4J API you're using, getRetweets(), does not return the IDs of users who retweeted.

Looking at the Twitter4J Twitter4J API docs we find getRetweeterIds(statusId) that returns the list of user IDs that retweed a particular tweet indicated by statusId.

MrJLP
  • 978
  • 6
  • 14