28

我似乎无法回复特定的推文:

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

有人有想法么?我觉得我在这里错过了一些简单的东西......

提前致谢。

4

6 回答 6

30

只是发布解决方案,这样其他人就不会像我一样遭受痛苦。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 末尾的一长串数字。祝你好运!

于 2019-07-19T19:46:46.853 回答
23

我遇到了同样的问题,但幸运的是我找到了解决方案。您只需要在推文中包含用户的 screen_name 即可:

api.update_status('@<username> My status update', tweetId)
于 2012-05-21T00:36:34.717 回答
17

你也可以做

api.update_status("my update", in_reply_to_status_id = tweetid)
于 2012-02-18T21:37:25.663 回答
15

那么,这很简单。我必须使用 @ 表示法指定推文是针对谁的。

api.update_status('My status update @whoIReplyTo',tweetId) 
于 2012-11-09T21:52:42.117 回答
2

我发现在指定我要回复的推文时,我必须包含推文的 ID 字符串(而不是实际的 ID 号)

api.update_status('@whoIReplyTo my reply tweet',tweetIdString) 
于 2017-05-17T00:55:26.670 回答
1

这似乎是 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 应用程序上,您可以在不嵌入您要回复的人的用户名的情况下进行回复。

于 2017-11-07T13:35:31.523 回答