How to send direct messages from the api?

php

#1

I’m trying this way, following the documentation on the official twitter page https://developer.twitter.com/en/docs/direct-messages/sending-and-receiving/api-reference/new-event

$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $oauth_token, $oauth_token_secret);

$data = [
    'event' => [
        'type' => 'message_create',
        'message_create' => [
            'target' => [
                'recipient_id' => 'xxxxxx'
            ],
            'message_data' => [
                'text' => 'Hello World!'
            ]
        ]
    ]
];


$content = $connection->post("direct_messages/events/new",['content-type: application/json' => $data]);

can someone please give me a little guidance please.

I do not get any error message, I can not see an answer


#2

It looks like you might be using TwitterOAuth in which case you are not calling post quite right.

$content = $connection->post("direct_messages/events/new", $data, true);

#3

Thank you, Mr. Abraham.
yes I do, I’m using the TwitterAOuth library for php.
I have done as I indicated and it has worked, thank you very much for your help. :slight_smile: :man_technologist:t4:
Have a good day.