简体   繁体   中英

How to remove retweet using twitter4j

Twitter4j 2.x had a method called getRetweetedByMe which could be used to delete a retweet. However, I am using twitter4j 3.0 and that method has been removed. I tried another solution but I am getting a error saying I can't removes someone else status. How can I accomplish removing retweets with this version of twitter4j.

My Approach:

        List<Status> retweets = twitter.getRetweets(statusId);
        for (Status retweet : retweets)
            if (retweet.getRetweetedStatus().getId() == statusId)
                twitter.destroyStatus(retweet.getRetweetedStatus().getId());

I found out easier way (and probably a way which creators of the API wanted us to use). Part of my "unretweet" method:

long myRetweetId = status.getId(); if (status.getUser().getId() != getCurrentUser().getId()) { // not my retweet, but the original tweet myRetweetId = status.getCurrentUserRetweetId(); // <- } twitter.destroyStatus(myRetweetId);

Working with Twitter4J 4.0.1 .

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