【发布时间】:2018-09-03 05:29:30
【问题描述】:
有没有办法在给定推文 ID 的情况下检查推文是否是回复而不是原始推文?如果是这样,有没有办法获取原始推文回复的推文的 ID?
【问题讨论】:
标签: python twitter wrapper tweepy twython
有没有办法在给定推文 ID 的情况下检查推文是否是回复而不是原始推文?如果是这样,有没有办法获取原始推文回复的推文的 ID?
【问题讨论】:
标签: python twitter wrapper tweepy twython
查看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)
【讨论】: