Tweepy - 仅回复推文作者
Tweepy - Reply only to Tweet author
我使用 Tweepy 作为 Twitter 上的机器人回复某些推文。我希望回复只针对推文的作者,而不是推文中可能提及的任何其他用户。
目前我用这个回复:
reply_status = api.update_status(status = 'tweet content', in_reply_to_status_id = tweet.id, auto_populate_reply_metadata=True)
此电话回复原始推文中提到的所有用户。我注意到 update_status
函数中有一个 exclude_reply_user_ids=
选项。但是,这需要要排除的用户 ID 列表。
- 如何获取推文中提到的用户 ID 列表?
- 有没有更简单的只回复作者的方法?
我想避免必须在推文开头写用户名,如果我不使用 auto_populate_reply_metadata=True
(请参阅 this),我将需要这样做。
How do I get a list of user ids mentioned in a tweet?
您可以使用状态的 entities
属性/Tweet object, which is an Entities object with a user_mentions
attribute. This will give you an array of User mention objects,并且您可以使用每个状态的 id
或 id_str
字段。
Is there a simpler way to reply only to the author?
I would like to avoid having to write the username at the beginning of the tweet, which I would need to do if I didn't use auto_populate_reply_metadata=True
是的,通过在推文开头手动添加提及。
您可以通过检索推文作者的屏幕名称以编程方式执行此操作,例如tweet.user.screen_name
.
否则,如果您使用 auto_populate_reply_metadata
,排除提及的唯一方法是使用 exclude_reply_user_ids
。
我使用 Tweepy 作为 Twitter 上的机器人回复某些推文。我希望回复只针对推文的作者,而不是推文中可能提及的任何其他用户。
目前我用这个回复:
reply_status = api.update_status(status = 'tweet content', in_reply_to_status_id = tweet.id, auto_populate_reply_metadata=True)
此电话回复原始推文中提到的所有用户。我注意到 update_status
函数中有一个 exclude_reply_user_ids=
选项。但是,这需要要排除的用户 ID 列表。
- 如何获取推文中提到的用户 ID 列表?
- 有没有更简单的只回复作者的方法?
我想避免必须在推文开头写用户名,如果我不使用 auto_populate_reply_metadata=True
(请参阅 this),我将需要这样做。
How do I get a list of user ids mentioned in a tweet?
您可以使用状态的 entities
属性/Tweet object, which is an Entities object with a user_mentions
attribute. This will give you an array of User mention objects,并且您可以使用每个状态的 id
或 id_str
字段。
Is there a simpler way to reply only to the author?
I would like to avoid having to write the username at the beginning of the tweet, which I would need to do if I didn't use
auto_populate_reply_metadata=True
是的,通过在推文开头手动添加提及。
您可以通过检索推文作者的屏幕名称以编程方式执行此操作,例如tweet.user.screen_name
.
否则,如果您使用 auto_populate_reply_metadata
,排除提及的唯一方法是使用 exclude_reply_user_ids
。