Search code examples
twittertwitter4j

number of favorite and number of retweet from user to user in Twitter


I need to do the following For each follower to specific user in Twitter , I need number of favorite and number of retweet this user do For example : for user A, suppose userB is userA's follower, I need number of favorite and number of retweet userB do for userA's Tweets

thanks


Solution

  • For the numbers of favorites you could check every favorite of user B and check if is from user A. I suppose that you already have the followers, so

    for (User B : followers){
    ResponseList<Status> favorites = t.getFavorites(B.getId()); // t is your Twitter Instance
    for(Status f : favorites)
    if(A.getId() == B.getUser().getId()) countF++;
    }
    

    For the number of retweets, you could do the same. I suppose that you already have the tweets by a follower (you could get up to 3200 with the API)

    for(Status sB : StatusesB)
    if (sB.isRetweet()){ 
    if(A.getId() == sB.getRetweetedStatus().getUser().getId()) countRT++;
    }