How to get favorite count of a retweet?

twitter4j
java
favorites

#1

Hi guys I am trying to get the favorite count of a retweet but always it returns 0. I am using Twitter4j.

Does anybody knows what is happen?

My code:
Status status = twitter.showStatus(Long.parseLong(tweetID));
int favorites = status.getFavoriteCount(); // favorites always is 0


#2

What is the Tweet ID you are using?

You may need to access the inner Tweet object inside the Retweet in order to get an accurate favourite count. I don’t know for sure how to do that in Twitter4J.


#3

Yep - try this instead:

Status status = twitter.showStatus(Long.parseLong(tweetID));
int favorites = (status.isRetweet()) ? 
    status.getRetweetedStatus().getFavoriteCount() : 
    status.getFavoriteCount();

If the status is a retweet, getFavoriteCount from retweeted status, else getFavoriteCount from the tweet itself.


#4

Thank you very much for your answer andypiper. You alright I have to access to the Inner Tweet object.
Thanks!!!


#5

Thank you very much IgorBrigadir That code works so nice. :slight_smile:


#6