Reply to Tweet with Tweepy - Python

六眼飞鱼酱① 提交于 2019-12-03 15:22:21

问题


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.


回答1:


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)



回答2:


You can also do

api.update_status("my update", in_reply_to_status_id = tweetid)



回答3:


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) 



回答4:


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!




回答5:


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) 



回答6:


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.



来源:https://stackoverflow.com/questions/9322465/reply-to-tweet-with-tweepy-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!