简体   繁体   English

Twitter API:检查推文是否为转推

[英]Twitter API: Check if a tweet is a retweet

I have found this question .我发现了这个问题 However I think this has changed on API version 1.1.但是我认为这在 API 1.1 版上有所改变。

If I use the search/tweets method, how can I see if the tweet is a RT?如果我使用search/tweets方法,如何查看推文是否为 RT? I see that the retweeted field always returns false .我看到retweeted的字段总是返回false Is there another field I can use for this answer?我可以使用另一个字段来回答这个问题吗?

If it's a retweet, the tweet will contain a property named retweeted_status .如果是转推,则推文将包含一个名为retweeted_status的属性。 To be complete, retweeted_status will not appear if the tweet is not a retweet.完整地说,如果推文不是转推,则不会出现retweeted_status More info at: Tweets .更多信息在: 推文

By simply checking the property name通过简单地检查属性名称

"retweeted_status" “转推状态”

if you does not find then it's not RT.如果你没有找到,那么它不是 RT。

As @Joe Mayo said, check for the retweeted_status key on the status object.正如@Joe Mayo 所说,检查状态对象上的retweeted_status键。

I have an example that is not caught by @Apoorv Ashutosh's suggestion.我有一个没有被@Apoorv Ashutosh 的建议抓住的例子。

See: https://twitter.com/gppvt/status/474162466776449024 this will redirect (because it is a retweet) to the original tweet.请参阅: https ://twitter.com/gppvt/status/474162466776449024 这将重定向(因为它是转推)到原始推文。 However if you get this tweet through the twitter API, it has retweeted_status .但是,如果您通过 twitter API 获得这条推文,它就有retweeted_status Notice the text does not contain "RT".请注意,文本不包含“RT”。

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 完成,则转推字段为 false,因此在这种情况下,只需在所有推文的“文本”字段中搜索此模式

RT @

This pattern can be of help, but I don't think there is any other function for this.这种模式可能会有所帮助,但我认为没有任何其他功能。

The retweeted_status property will exist if the received tweet was retweeted, else you will get the AttributeError error.如果收到的推文被转推,则retweeted_status属性将存在,​​否则您将收到AttributeError错误。 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"

Just to add a bit more.只是为了补充一点。 (using twitter gem (ruby language)) (使用 twitter gem(红宝石语言))

You can check if its a retweet by checking the tweet and then getting what you need from the retweeted_status hash您可以通过检查推文然后从 retweeted_status 哈希中获取您需要的内容来检查它是否是转推

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

As everyone else has mentioned, you can check to see if the retweeted_status property exists in the response subfield for that Tweet.正如其他人所提到的,您可以检查该推文的响应子字段中是否存在retweeted_status属性。

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. 但是,根据 API 的当前版本,每个 Tweet 对象都有retweeted字段,该字段存储一个布尔值(True 或 False),该值将告诉您 Tweet 是否已被转发。

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.在这种情况下,我必须使用quoted_status字段来获取原始推文,而不是使用retweeted_status字段。

对于使用Hydrator 1并依赖其CSV导出水合JSONL文件的人:您可以检查reweet_id (不,这不是版本0.0.12中的错字),如果它是NA ,那么它就是我发现的原始推文。

original_twitter_tweets = twitter_csv_data %>% filter(is.na(reweet_id))

I've seen that the text of retweets has a "RT @..." that separates them from normal tweets.我已经看到转推的文本有一个“RT @...”,将它们与普通推文区分开来。

In Python you can use the code below to recognize them:在 Python 中,您可以使用下面的代码来识别它们:

tweettext = str( tweet.text.lower())
if tweettext.startswith("rt @") == True:
    print(tweet.id)

that tweet variable is tweet object.该推文变量是推文对象。 Also, you can use Tweepy for an easier way of handling twitter Api此外,您可以使用 Tweepy 更轻松地处理 twitter Api

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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