Reputation: 309
I use Tweepy to reply to certain Tweets as a bot on Twitter. I would like the reply to be addressed only to the author of the Tweet and not to any other users that may be mentioned in it.
Currently I use this to reply:
reply_status = api.update_status(status = 'tweet content', in_reply_to_status_id = tweet.id, auto_populate_reply_metadata=True)
This call replies to all users mentioned in the original tweet. I've noticed there is an exclude_reply_user_ids=
option in the update_status
function. This however requires a list of user IDs to exclude.
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
(see this).
Upvotes: 0
Views: 440
Reputation: 5157
How do I get a list of user ids mentioned in a tweet?
You can use the entities
attribute of the Status/Tweet object, which is an Entities object with a user_mentions
attribute. This will give you an array of User mention objects, and you can use the id
or id_str
fields of each one.
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
Yes, by manually including the mention at the start of the Tweet.
You can do this programatically by retrieving the screen name of the author of the Tweet, e.g. tweet.user.screen_name
.
Otherwise, if you're using auto_populate_reply_metadata
, the only way to exclude mentions is using exclude_reply_user_ids
.
Upvotes: 0