jublo / codebird-php

Easy access to the Twitter REST API, Direct Messages API, Account Activity API, TON (Object Nest) API and Twitter Ads API — all from one PHP library.
https://www.jublo.net/projects/codebird/php
GNU General Public License v3.0
775 stars 237 forks source link

POST direct_messages/events/new (message_create) #234

Closed gentjana closed 6 years ago

gentjana commented 6 years ago

i'm using the below code for reply to a direct message, but i receive error: 400. What i'm doing wrong? Please help is important to do the changes in twitter api before 19 June. Thanks.

ini_set('display_errors', 1); require_once('TwitterAPIExchange.php');

$settings = array( 'oauth_access_token' => '', 'oauth_access_token_secret' => '', 'consumer_key' => '', 'consumer_secret' =>'', );

$twitter = new TwitterAPIExchange($settings);

$url = "https://api.twitter.com/1.1/direct_messages/events/new.json";

    $method = 'POST';

    $params = json_encode(array(
            'event' => array(
                'type' => 'message_create',
                'message_create' => array(
                    'target' => array(
                        "recipient_id" => '123'),
                    'message_data' => array(
                        'text' => 'Hello'
                    )
                )
            )
        )
    );

    $twitter->buildOauth($url, $method)
        ->performRequest(true,
            array(CURLOPT_HTTPHEADER => array(
                'Content-Type: application/json'
            ), CURLOPT_POSTFIELDS => $params));