Reply to Tweet with Tweepy – Python
Question:
I can’t seem to get tweepy to work with replying to a specific tweet:
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
api = tweepy.API(auth)
### at this point I've grabbed the tweet and loaded it to JSON...
tweetId = tweet['results'][0]['id']
api.update_status('My status update',tweetId)
The api says it takes optional parameters and in_reply_to_status_id is the first, but it seems to be ignoring it altogether. This script will post an updated status, but it does not link it as a reply to the tweetId that I’m passing.
API for reference: http://code.google.com/p/tweepy/wiki/APIReference#update_status
Anyone have any ideas? I feel like I’m missing something simple here…
Thanks in advance.
Answers:
You can also do
api.update_status("my update", in_reply_to_status_id = tweetid)
I ran into the same problem, but luckily I found the solution. You just need to include the user’s screen_name in the tweet:
api.update_status('@<username> My status update', tweetId)
Well then, it was something simple. I had to specify who the tweet was directed towards using the @ notation.
api.update_status('My status update @whoIReplyTo',tweetId)
I discovered that I had to include the tweet’s ID string (rather than actual ID number) when specifying the tweet that I was replying to
api.update_status('@whoIReplyTo my reply tweet',tweetIdString)
This seems to be a bug in Tweepy – even if you make a call to api.update_status with the correct parameters set,
api.update_status(status=your_status, in_reply_to_status=tweet_to_reply_to.id)
the tweet will not be a reply. In order to get a reply, you need to mention the user you want to reply to AND specify the correct in_reply_to_status id.
reply_status = "@%s %s" % (username_to_reply_to, your_status)
api.update_status(status=reply_status, in_reply_to_status=tweet_to_reply_to.id)
Keep in mind though – Tweepy and Twitter’s servers still enforce a maximum number of 140 characters, so make sure you check that
len(reply_status) <= 140
Again, I think this is a bug because on the Twitter app, you can reply without embedding the username of the person to whom you’re replying.
Just posting the solution so no someone else suffers the way I did.
Twitter updated the API and added an option named auto_populate_reply_metadata
All you need to do is set that to true, and the leave the rest as should be. Here is a sample:
api.update_status(status = 'your reply', in_reply_to_status_id = tweetid , auto_populate_reply_metadata=True)
Also, the status_id is the long set of digits at the end of the tweet URL. Good Luck!
reply_status = "@%s %s" % (tweet.user.screen_name, "type your reply here")
api.update_status(status=reply_status, in_reply_to_status_id=tweet.id)
this is the last correct form, I just test it a few minutes ago
I can’t seem to get tweepy to work with replying to a specific tweet:
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
api = tweepy.API(auth)
### at this point I've grabbed the tweet and loaded it to JSON...
tweetId = tweet['results'][0]['id']
api.update_status('My status update',tweetId)
The api says it takes optional parameters and in_reply_to_status_id is the first, but it seems to be ignoring it altogether. This script will post an updated status, but it does not link it as a reply to the tweetId that I’m passing.
API for reference: http://code.google.com/p/tweepy/wiki/APIReference#update_status
Anyone have any ideas? I feel like I’m missing something simple here…
Thanks in advance.
You can also do
api.update_status("my update", in_reply_to_status_id = tweetid)
I ran into the same problem, but luckily I found the solution. You just need to include the user’s screen_name in the tweet:
api.update_status('@<username> My status update', tweetId)
Well then, it was something simple. I had to specify who the tweet was directed towards using the @ notation.
api.update_status('My status update @whoIReplyTo',tweetId)
I discovered that I had to include the tweet’s ID string (rather than actual ID number) when specifying the tweet that I was replying to
api.update_status('@whoIReplyTo my reply tweet',tweetIdString)
This seems to be a bug in Tweepy – even if you make a call to api.update_status with the correct parameters set,
api.update_status(status=your_status, in_reply_to_status=tweet_to_reply_to.id)
the tweet will not be a reply. In order to get a reply, you need to mention the user you want to reply to AND specify the correct in_reply_to_status id.
reply_status = "@%s %s" % (username_to_reply_to, your_status)
api.update_status(status=reply_status, in_reply_to_status=tweet_to_reply_to.id)
Keep in mind though – Tweepy and Twitter’s servers still enforce a maximum number of 140 characters, so make sure you check that
len(reply_status) <= 140
Again, I think this is a bug because on the Twitter app, you can reply without embedding the username of the person to whom you’re replying.
Just posting the solution so no someone else suffers the way I did.
Twitter updated the API and added an option named auto_populate_reply_metadata
All you need to do is set that to true, and the leave the rest as should be. Here is a sample:
api.update_status(status = 'your reply', in_reply_to_status_id = tweetid , auto_populate_reply_metadata=True)
Also, the status_id is the long set of digits at the end of the tweet URL. Good Luck!
reply_status = "@%s %s" % (tweet.user.screen_name, "type your reply here")
api.update_status(status=reply_status, in_reply_to_status_id=tweet.id)
this is the last correct form, I just test it a few minutes ago