简体   繁体   中英

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

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.

Oh thanks ! I was looking for a method in the FavoritesResources, forgot to check out Status' methods for this one.

Thank you, have a good day !

Edit : Seems that this method returns if a tweet has been favorited in general, not by me in particular. Back to start :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM