Twitter API: Check if a tweet is a retweet

前端 未结 9 2341
南笙
南笙 2020-12-15 05:33

I have found this question. However I think this has changed on API version 1.1.

If I use the search/tweets method, how can I see if the tweet is a RT?

相关标签:
9条回答
  • 2020-12-15 05:54

    The retweeted_status property will exist if the received tweet was retweeted, else you will get the AttributeError error. In the case, you want to get rid of retweeted tweets:

    def on_status(self, status):
        try:
            print "Retweeted ************* \n" + str(status.retweeted_status)
            return 
        except AttributeError:
            print "there is no attribut with name retweeted_status"
    
    0 讨论(0)
  • 2020-12-15 05:54

    As everyone else has mentioned, you can check to see if the retweeted_status property exists in the response subfield for that Tweet.

    However, per the current version of the API, every Tweet object has the field retweeted that stores a boolean value (True or False) that will tell you if a Tweet has been retweeted.

    0 讨论(0)
  • 2020-12-15 05:58

    By simply checking the property name

    "retweeted_status"

    if you does not find then it's not RT.

    0 讨论(0)
  • 2020-12-15 05:58

    Make sure your "re-tweet" is not actually a quote of an another tweet. In this case, I had to use the quoted_status field to get the original tweet, rather than the retweeted_status one.

    0 讨论(0)
  • 2020-12-15 06:03

    Just to add a bit more. (using twitter gem (ruby language))

    You can check if its a retweet by checking the tweet and then getting what you need from the retweeted_status hash

    t = client.status(#########) #function that obtains tweet based on ID where # = tweet ID
    puts t.retweeted_status? # returns true or false
    t.retweeted_status # returns the actual hash for that
    
    0 讨论(0)
  • 2020-12-15 06:07

    If it's a retweet, the tweet will contain a property named retweeted_status. To be complete, retweeted_status will not appear if the tweet is not a retweet. More info at: Tweets.

    0 讨论(0)
提交回复
热议问题