Updated Twitter Direct Messages API with Tweepy

Viewed 3092

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 Answers

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.

Related