Twitter API: Check if a tweet is a retweet

2019-01-23 13:14发布

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? I see that the retweeted field always returns false. Is there another field I can use for this answer?

标签: twitter
7条回答
▲ chillily
2楼-- · 2019-01-23 13:26

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.

查看更多
太酷不给撩
3楼-- · 2019-01-23 13:26

By simply checking the property name

"retweeted_status"

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

查看更多
仙女界的扛把子
4楼-- · 2019-01-23 13:28

The retweeted field is false if the retweet is not done using the retweet button but rahter via RT, so in such a case, just search the "text" field of all tweets for this pattern

RT @

This pattern can be of help, but I don't think there is any other function for this.

查看更多
劫难
5楼-- · 2019-01-23 13:29

As @Joe Mayo said, check for the retweeted_status key on the status object.

I have an example that is not caught by @Apoorv Ashutosh's suggestion.

See: https://twitter.com/gppvt/status/474162466776449024 this will redirect (because it is a retweet) to the original tweet. However if you get this tweet through the twitter API, it has retweeted_status. Notice the text does not contain "RT".

查看更多
Ridiculous、
6楼-- · 2019-01-23 13:33

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.

查看更多
姐就是有狂的资本
7楼-- · 2019-01-23 13:37

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
查看更多
登录 后发表回答