Search code examples
javatwittertwitter4j

Using Twitter4j how do i get all the list of Favorited tweets by a particulate user


I want all the list of tweets which are favorited by a twitter user account.

I have done some sample code that will give me all the posts that the user posted but i want all the tweets that the user favorited.

public List getAllTweetsOfUser(Twitter twitter, String user) {
    if (user != null && !user.trim().isEmpty()) {
        List statuses = new ArrayList();
        int pageno = 1;
        while (true) {
            try {
                int size = statuses.size();
                Paging page = new Paging(pageno++, 100);
                statuses.addAll(twitter.getUserTimeline(user, page));
                if (statuses.size() == size) {
                    break;
                }
            } catch (TwitterException e) {
            }
        }
        return statuses;
    } else {
        return null;
    }
}

Can any one help me in this..


Solution

  • I have tried like below..

    ResponseList<Status> status = twitter.getFavorites(twitterScreenName);
    

    It given me the favorite tweets of the user which i have passed as a parameter. But the problem here is i am able to get only 20 favorites, though the user has so many tweets.

    ResponseList<Status> status = twitter.getFavorites(twitterScreenName, paging);
    

    I tried with the paging but i am not sure how to use this paging. So i am getting the top 20 favorites using my first code. If anybody tried this then please share the info like how to get all favorites of a given user.