使用Tweepy更新的Twitter直接消息API

3

Twitter更新了他们的消息API(https://developer.twitter.com/en/docs/direct-messages/sending-and-receiving/api-reference/new-event),今天我写的所有关于发送直接信息的Python代码通过Tweepy都停止工作了,而且我似乎无法让它正常工作。这是我现在拥有的代码:

direct_message = api.send_direct_message(user=username, text=message_text)

然而,我从Twitter收到以下错误响应:
[{'code': 34, 'message': 'Sorry, that page does not exist.'}]

我对如何使用Tweepy实现新的API更改感到困惑。直到今天它一切都运行良好,但现在却无法工作... 我可以100%确定用户已经通过身份验证并具有发送消息的权限,但仍然收到错误提示。


看起来 tweepy 目前还没有更新以支持新的端点。有一些 开放的 Github 问题与一些解决方法 可能会帮助你,但在库被更新之前,这并不是非常直接的。 - Andy Piper
我有同样的问题。我们需要等待tweepy的更新 :-( - FdMon
你有没有检查GitHub上可用的解决方法?https://github.com/tweepy/tweepy/issues/1081 - FdMon
1个回答

0

更新Tweepy。在Twitter应用程序中检查其权限。撤销密钥。 现在尝试这个简单的代码。

 def direct_message(api):
 logger.info("Start send mensage")

 for dm in tweepy.Cursor(api.followers_ids).items(10):
       #edit the msg parameter     
      api.send_direct_message(dm, 'Watching our new indie game trailer from my creator @AGTAStudios on Youtube : https://youtu.be/qGC-0toodmA')
      logger.info("msg send") 

def main():
    api = create_api()
    direct_message(api)


if __name__ == "__main__":
    main()

如果它不工作,请回复错误信息。
希望这能有所帮助。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接