用Tweepy更新了Twitter直接消息API

2024-06-01 02:19:17 发布

您现在位置:Python中文网/ 问答频道 /正文

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

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

但是,我从Twitter收到以下错误响应:

^{pr2}$

我不知道如何用Tweepy实现新的API更改。直到今天它都工作得很好,现在它不工作了。。。我百分之百确定用户已经过身份验证,并有权发送消息,但我仍然收到错误。在


Tags: 代码texthttpscomapi消息developermessage
1条回答
网友
1楼 · 发布于 2024-06-01 02:19:17

更新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()

如果不起作用,请用错误回答。在

希望这有帮助。在

相关问题 更多 >