Updated Twitter Direct Messages API with Tweepy

送分小仙女□ 提交于 2020-01-13 19:04:57

问题


Twitter updated their messages API (https://developer.twitter.com/en/docs/direct-messages/sending-and-receiving/api-reference/new-event) today and all of the Python code I had written via Tweepy relating to sending Direct Messages has stopped working and I can't seem to get it to work. This is the code I have right now:

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

However, I am getting the following error response from Twitter:

[{'code': 34, 'message': 'Sorry, that page does not exist.'}]

I am confused about how to implement the new API changes with Tweepy. It was working perfectly fine until today and now it won't work... I am 100% sure the user is authenticated and has the permissions to send messages and I am still getting the error.


回答1:


Update the Tweepy. In twitter app check permission to it. Revoke keys. Now try this simples code.

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

If it's dont work, reply with error.

Hope this helps.



来源:https://stackoverflow.com/questions/52377403/updated-twitter-direct-messages-api-with-tweepy

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