I’m using the below code for replying to a direct message, but returns me this error: “{“errors”:[{“code”:215,“message”:“Bad Authentication data.”}]}”. Please help is important to fix it ASAP. Thanks.
$settings = array(
'oauth_access_token' => $channel->accessToken,
'oauth_access_token_secret' => $channel->accessTokenSecret,
'consumer_key' => $twApp->apiKey,
'consumer_secret' => $twApp->apiSecret
);
$twitter = new TwitterAPIExchange($settings);
$url = 'https://api.twitter.com/1.1/direct_messages/events/new.json';
$params = json_encode(array(
'event' => array(
'type' => 'message_create',
'message_create' => array(
'target' => array(
"recipient_id" => $this->fromUserId),
'message_data' => array(
'text' => $text
)
)
)
)
);
$requestMethod = 'POST';
echo $twitter->buildOauth($url, $requestMethod)
->performRequest(true,
array(CURLOPT_HTTPHEADER => array(
'Content-Type: application/json'
), CURLOPT_POSTFIELDS => $params)
);