我正在尝试创建一段代码,以简单回复(给定)推文,我只知道api.update_status
用于发送推文,但不知道如何回复推文,我做了一些研究,但所有内容都已过时,“in_reply_to_status_id”似乎不再起作用。
api = tweepy.API(auth)
api.update_status
import tweepy
client = tweepy.Client(consumer_key='YOUR_CONSUMER_KEY',
consumer_secret='YOUR_CONSUMER_SECRET',
access_token='YOUR_ACCESS_TOKEN',
access_token_secret='YOUR_ACCESS_TOKEN_SECRET')
client.create_tweet(text='Some reply', in_reply_to_tweet_id=42)
v1.1
,则需要在状态文本中包含@username
,其中username是所引用推文的作者。 这在这里有所描述。comment = '@usernameOfTweet Test Reply'
res = api.update_status(comment, in_reply_to_status_id=42)
还可以使用 auto_populate_reply_metadata=True
,参见这个 Github 问题中的讨论。
comment = 'Test reply'
api.update_status(comment, in_reply_to_status_id=42, auto_populate_reply_metadata=True)
这也在文档中有描述。
auto_populate_reply_metadata - 如果将其设置为 true 并与 in_reply_to_status_id 一起使用,则会从原始推文中查找前导 @ 提及,并将其添加到新推文中。