send_direct_message returning 404 page not exist #535

Open
opened 2020-06-16 21:41:46 -07:00 by sherluck08 · 3 comments
sherluck08 commented 2020-06-16 21:41:46 -07:00 (Migrated from github.com)

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

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"))`
alexacallmebaka commented 2020-11-08 17:52:11 -08:00 (Migrated from github.com)

This may help.

[This](https://stackoverflow.com/questions/63240624/how-to-send-a-direct-message-with-twython) may help.
tadeoos commented 2021-05-13 08:53:41 -07:00 (Migrated from github.com)

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 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: ```python 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 commented 2021-05-13 09:02:12 -07:00 (Migrated from github.com)

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

The above comment is valid for 3.7.0 version. I see that in the newest version this should work correctly.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: code/twython#535
No description provided.