python-twitter-tools / twitter

Python Twitter API
http://mike.verdone.ca/twitter/
MIT License
3.19k stars 713 forks source link

The direct messages example no longer works #387

Closed endlisnis closed 3 years ago

endlisnis commented 6 years ago

The example of how to send a direct message:

# Send a direct message
t.direct_messages.new(
    user="billybob",
    text="I think yer swell!")

No longer works (there were some changes to the Twitter API).

I'm not sure this is the most simple method, but the only way I could get it to work was like this:

t.direct_messages.events.new(
    _json={
        "event": {
            "type": "message_create",
            "message_create": {
                "target": {
                    "recipient_id": t.users.show(screen_name="billybob")["id"]},
                "message_data": {
                    "text": "I think yer swell!"}}}})
RouxRC commented 6 years ago

You're totally right, the old way was deprecated by Twitter and your proposed way is also exactly how I ported it in a personal project. Would you like to submit a PR with a modification of the example in the readme?

endlisnis commented 6 years ago

I was actually hoping that something more user-friendly could be done about it. That's a very awkward method to send a direct message. It would be nice if there were a simpler interface for it.

RouxRC commented 6 years ago

I agree but it's the result of a complete change in Twitter's API inputs architecture for these specific new routes, I'm not sure what would be a good way to handle those in respect with the whole lib's philosophy. cc @sixohsix

endlisnis commented 6 years ago

I created a pull request as you suggested.