简体   繁体   English

使用Twython或Tweepy检查Tweet是否是答复?

[英]Using Twython or Tweepy to check if a Tweet is a reply?

Is there a way, given a tweet ID, to check if a tweet is a reply rather than an original tweet? 在给定了推文ID的情况下,是否可以检查某条推文是否为回复,而不是原始推文? If so, is there a way to get the ID of the tweet that the original tweet is in reply to? 如果是这样,是否有办法获取原始推文所回复的推文的ID?

Looking at Twitter Documentation you see that a tweet object has 查看Twitter文档,您会看到一个tweet对象具有

in_reply_to_status_id in_reply_to_status_id

Nullable. 可为空。 If the represented Tweet is a reply, this field will contain the integer representation of the original Tweet's ID. 如果所表示的Tweet是回复,则此字段将包含原始Tweet ID的整数表示。

Example: "in_reply_to_status_id":114749583439036416 示例:“ in_reply_to_status_id”:114749583439036416

Using tweepy you can do something like this: 使用tweepy可以执行以下操作:

user_tweets = constants.api.user_timeline(user_id=user_id, count=100)

    for tweet in user_tweets:
        if tweet.in_reply_to_status_id is not None:
            # Tweet is a reply
            is_reply = True
        else:
            # Tweet is not a reply
            is_reply = False

If you're looking for a specific tweet and you have the id then you want to use get_status like this: 如果您要查找特定的推文,并且具有ID, 则要使用get_status,如下所示:

tweet = constants.api.get_status(tweet_id)

if tweet.in_reply_to_status_id is not None:
    # Tweet is a reply
    is_reply = True
else:
    # Tweet is not a reply
    is_reply = False

Where api is: api在哪里:

auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth, wait_on_rate_limit=True)

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

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