【问题标题】:Using Twython or Tweepy to check if a Tweet is a reply?使用 Twython 或 Tweepy 来检查推文是否是回复?
【发布时间】:2018-09-03 05:29:30
【问题描述】:

有没有办法在给定推文 ID 的情况下检查推文是否是回复而不是原始推文?如果是这样,有没有办法获取原始推文回复的推文的 ID?

【问题讨论】:

    标签: python twitter wrapper tweepy twython


    【解决方案1】:

    查看Twitter Documentation 你会看到一个推文对象有

    in_reply_to_status_id

    可以为空。如果表示的推文是回复,则此字段将包含原始推文 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)
    

    【讨论】:

    • 这会检查整个用户时间线吗?我正在尝试测试特定的推文。
    • 我更新了答案以包含相关信息。
    • 你是最棒的!!!! - 你不会碰巧知道是否有办法获取回复最初响应的推文的 ID??
    • tweet.in_reply_to_status_id 要么是 None 要么是他们回复的推文的 id。
    • 噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢噢!你是100%正确的!!!非常感谢你!
    猜你喜欢
    • 2018-10-07
    • 2022-01-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多