birdy icon indicating copy to clipboard operation
birdy copied to clipboard

Direct Message

Open sharma-ji opened this issue 6 years ago • 1 comments

What about Direct Message API?

sharma-ji avatar Jul 09 '18 10:07 sharma-ji

@sharma-ji it doesn't appear that the library directly supports posting a JSON payload to the Twitter API endpoint for direct messages and that's why you wouldn't be able to do so without a hack. Here's a snippet I created for getting around this:

params = {'event': {'type': 'message_create',
                    'message_create': {
                        'message_data': {'text': message},
                        'target': {'recipient_id': user_id}}}}

path = client.api.direct_messages.events.new.get_path()
url = client.construct_resource_url(path)
response = client.make_api_call('POST', url, json=params)
status = client.handle_response('POST', response)

client is the UserClient object you would have created previously.

takinbo avatar Oct 29 '18 06:10 takinbo