twitteroauth: Direct message new API returning NULL

Hi Sir

I am using the following code and library functions to use twitter API’s

require "vendor/autoload.php";

use Abraham\TwitterOAuth\TwitterOAuth;
$consumerKey 					= 'vT********************RQy';
$consumerSecret 				= 'hdJqg*****************o************************MF0';
$accessToken 					= "8**********************************************a6I";
$accessSecret 					= "zYJ********************************************dRH";
$baseUrl 						=  "http://******************/";
$redirectURL 					= 'http://******************/';


$connection = new TwitterOAuth($consumerKey, $consumerSecret, $accessToken, $accessSecret);
$content = $connection->get("account/verify_credentials");
$connection->setTimeouts(10, 15);
echo "<pre>"; print_r($content);echo "</pre>"; 
$userId = "1027************96 ";

 $userDtaRes = $connection->get('users/lookup ', array('screen_name' => "Easemymarketing")); 
 print_r("<br/> user lookup API <br/>");
var_dump("<br/>".$connection->getLastHttpCode());
var_dump("<br/>".$connection->getLastApiPath());
var_dump("<br/>".$userDtaRes);



$data = [
    'event' => [
        'type' => 'message_create',
        'message_create' => [
            'target' => [
                'recipient_id' => $userId
            ],
            'message_data' => [
                'text' => "hi new dm messg to ashsi "
            ]
        ]
    ]
];

$result = $connection->post('direct_messages/events/new ', $data, true); // Note the true
print_r("<br/> USER send direct mesage api <br/>");
var_dump("<br/>".$connection->getLastHttpCode());

var_dump("<br/>".$result);

Always it returns NULL for each library, please guide me how to run the to fetch various API result and send the direct message event new.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 15 (6 by maintainers)

Most upvoted comments

There is a space end of new message endpoint, checking actual code for this space can be helpful maybe. Also this space exists in the JSON data part of https://twitteroauth.com/ main page doc.

$result = $connection->post('direct_messages/events/new ', $data, true); // Note the true