32

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.

mcriecken
  • 3,217
  • 2
  • 20
  • 23
  • 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) – mcriecken Feb 17 '12 at 03:52

7 Answers7

38

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!

George
  • 2,034
  • 1
  • 15
  • 16
Kanyesigye Akbr
  • 381
  • 1
  • 3
  • 2
24

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)
18

You can also do

api.update_status("my update", in_reply_to_status_id = tweetid)
bluish
  • 26,356
  • 27
  • 122
  • 180
Dave Kasper
  • 1,369
  • 1
  • 11
  • 18
  • THis should be the best option – user3378649 Feb 23 '15 at 04:00
  • 2
    This did not work for me. You do need to add the user's handle in the Tweet for it to be a reply. Otherwise it will count as a new Tweet from you, not a reply to an existent Tweet. – Diego Mora Cespedes Jan 28 '17 at 21:13
  • @DiegoMoraCespedes This is wrong (at least now it is). You have to add `auto_populate_reply_metadata=True` along with `in_reply_to_status_id`. This means that you *don't* have to add the user's handle in the Tweet in order for it to work. – pigeonburger Dec 11 '20 at 02:21
15

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) 
mcriecken
  • 3,217
  • 2
  • 20
  • 23
  • 1
    Worked first time. I was missing the tweet id number. Great question and answer - thanks! – Adjam Mar 23 '14 at 17:38
2

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) 
ckirksey3
  • 1,117
  • 9
  • 13
1

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.

Clay Coleman
  • 331
  • 3
  • 7
1
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

Alan
  • 11
  • 2