Search code examples
javaapitwitterjavafx-2twitter4j

Twitter4j check if tweet is favorited by myself


I'm creating a Twitter app in Java and I need to check out if some particular tweet is in my favorites.

I read the doc, but did'nt find out what function does that kind of thing (hoping there is one).

Does somebody know ?

Thanks


Solution

  • The Status interface has the following method:

     /**
         * Test if the status is favorited
         *
         * @return true if favorited
         * @since Twitter4J 1.0.4
         */
        boolean isFavorited();
    

    I made thw following example to show you how it works:

     ResponseList<Status> result = twitter.getFavorites();
            for (Status status : result)
            {
                System.out.println(status.getText());
                System.out.println(status.isFavorited());
            }
    

    You can test also with ne following code:

     QueryResult result = twitter.search(new Query("Some term"));
            for (Status status : result.getTweets())
            {
                System.out.println(status.getText());
                System.out.println(status.getFavoriteCount());
                System.out.println(status.isFavorited());
            }
    

    And you are going to see that some tweets has n number of favoriteCount but it is going to return false because it is not of your favorites.