geduldig / TwitterAPI

Minimal python wrapper for Twitter's REST and Streaming APIs
939 stars 263 forks source link

Direct Message #100

Closed leoheck closed 6 years ago

leoheck commented 6 years ago

Hi, I am playing with your API, and it is really cool. I have a question. Do you have any examples of how to send direct messages? Thank you.

geduldig commented 6 years ago

Here you are...

user_id = <recipient's user id>
message_text = <you DM text>

event = '{"event":{"type":"message_create","message_create":{"target":{"recipient_id":"%s"},"message_data":{"text":"%s"}}}}' % (user_id, message_text)

r = api.request('direct_messages/events/new', event)
print(r.status_code)
geduldig commented 6 years ago

Added to examples... https://github.com/geduldig/TwitterAPI/blob/master/examples/direct_message.py