简体   繁体   中英

Delete retweet using Twitter gem

I'm working on a project that uses the Twitter ruby gem, and I want to be able to "undo" a retweet. I've had no luck so far by trying to search for the original tweet and then removing the first occurrence, if it belongs to me. There's an unfavorite method, but no unretweet which is annoying. The only helpful thing so far is that I know if it has been retweeted or not. For this purpose, I can only see tweets that mention me.

您可以尝试以下方法: Twitter.status_destroy(id)

As @dx7 says, you need to know ahead of time the ID of the original tweet, or the info related to the retweet and save it if you intend to undo the retweet.

If you have the ID of the original retweet, you can use Twitter.retweets(tweet_id, options = {}) to get a list of retweets and then you can find the one by the current_user and destroy it as @dx7 says.

Otherwise, you can try Twitter.retweeted_by_user(user, options = {}) to get a list of the last 20 retweets (default) by that user to find the retweet you want, get its ID, and destroy it.

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