簡體   English   中英

使用Twython或Tweepy檢查Tweet是否是答復?

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

在給定了推文ID的情況下,是否可以檢查某條推文是否為回復,而不是原始推文? 如果是這樣,是否有辦法獲取原始推文所回復的推文的ID?

查看Twitter文檔,您會看到一個tweet對象具有

in_reply_to_status_id

可為空。 如果所表示的Tweet是回復,則此字段將包含原始Tweet ID的整數表示。

示例:“ in_reply_to_status_id”:114749583439036416

使用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

如果您要查找特定的推文,並且具有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

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