twython icon indicating copy to clipboard operation
twython copied to clipboard

send_direct_message returning 404 page not exist

Open sherluck08 opened this issue 4 years ago • 3 comments

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

sherluck08 avatar Jun 17 '20 04:06 sherluck08

This may help.

alexacallmebaka avatar Nov 09 '20 01:11 alexacallmebaka

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 {}

tadeoos avatar May 13 '21 15:05 tadeoos

The above comment is valid for 3.7.0 version. I see that in the newest version this should work correctly.

tadeoos avatar May 13 '21 16:05 tadeoos