[英]Reply to Tweet with Tweepy - Python
我似乎无法回复特定的推文:
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)
api 表示它采用可选参数,in_reply_to_status_id 是第一个,但它似乎完全忽略了它。 此脚本将发布更新状态,但不会将其链接为对我传递的 tweetId 的回复。
API 供参考:http://code.google.com/p/tweepy/wiki/APIReference#update_status
有人有主意吗? 我觉得我在这里缺少一些简单的东西......
提前致谢。
我遇到了同样的问题,但幸运的是我找到了解决方案。 你只需要在推文中包含用户的 screen_name :
api.update_status('@<username> My status update', tweetId)
只是发布解决方案,所以没有其他人像我那样受苦。 Twitter 更新了 API 并添加了一个名为auto_populate_reply_metadata
的选项
您需要做的就是将其设置为 true,其余的保持原样。 这是一个示例:
api.update_status(status = 'your reply', in_reply_to_status_id = tweetid , auto_populate_reply_metadata=True)
此外,status_id 是推文 URL 末尾的一长串数字。 祝你好运!
你也可以这样做
api.update_status("my update", in_reply_to_status_id = tweetid)
那么,这很简单。 我必须使用@ 表示法指定推文的对象是谁。
api.update_status('My status update @whoIReplyTo',tweetId)
我发现在指定我正在回复的推文时,我必须包含推文的 ID 字符串(而不是实际的 ID 号)
api.update_status('@whoIReplyTo my reply tweet',tweetIdString)
这似乎是 Tweepy 中的一个错误——即使您使用正确的参数集调用api.update_status ,
api.update_status(status=your_status, in_reply_to_status=tweet_to_reply_to.id)
这条推文不会是回复。 为了获得回复,您需要提及要回复的用户并指定正确的 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)
不过请记住——Tweepy 和 Twitter 的服务器仍然强制执行最多 140 个字符,所以一定要检查一下
len(reply_status) <= 140
同样,我认为这是一个错误,因为在 Twitter 应用程序上,您可以回复而不嵌入您回复的人的用户名。
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)
这是最后一个正确的形式,我几分钟前刚测试过
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.