twython
twython copied to clipboard
send_direct_message returning 404 page not exist
I'm trying to send DM with this it's returning 404 sorry page not exist.
here's what I tried
api.send_direct_message(type='message_create', recipient_id="id", message_data="test message"))
This may help.
The 404 response is due to the erroneous endpoint definition. In the EndpointsMixin.send_direct_message
the URL is defined as direct_messages/new
it should be direct_messages/events/new
. Unfortunately, this is not enough. The example given in the SO answer linked above is not working because of the _transparent_params
helper function. We can't pass the whole event dict to the post
method:
twitter.send_direct_message(event = {"type": "message_create",
"message_create":{"target": {"recipient_id": ID goes here},
"message_data":
{"text": "Hello World!"}}})
because _transparent_params
can't handle dictionaties with embedded dictionaries and our params getting truncated to {}
The above comment is valid for 3.7.0 version. I see that in the newest version this should work correctly.