views:

33

answers:

2

Hello all! I wonder if anyone could help me to figure out how to get the amount, as a Java long number, of all retweets of me looking at a specific user, using either twitters API or Twitter4J. The code below gives me only the last 100 retweets, using Twitter4J!


public static long getReTweets(){
   long amount = 0;
   Twitter tweeter = new TwitterFactory().getOAuthAuthorizedInstance(MyUser.getUserAccessToken());
   try {
      ResponseList retweets = tweeter.getRetweetsOfMe();
      amount = retweets.size();
    } catch (TwitterException e) {
      e.printStackTrace();
    }
    return amount;
}
+1  A: 

with Twitter4J you can call the getRetweetsOfMe(Paging) to resolve additional pages of retweets. The 100 result count is the API limit so you should keep calling the method till you're done.

Bivas
A: 

According to Twitter Developer site, retweet_of_me, you can allow a count of maximum 100 results.

count Specifies the number of records to retrieve. Must be less than or equal to 100.

http://api.twitter.com/1/statuses/retweets_of_me.json?count=5

So, if you want to get all retweet_of_me, you'll need to page through all your retweets_of_me and do a count of a 100. Sum up all resulting counts till you don't get any results from a page and that's the total retweets_of_me.

PS. There more pages you have, the more work it might take for you to page all of it.

The Elite Gentleman