Twitter Send Direct Messages Through Codeigniter

Twitter Send Direct Messages Through Codeigniter

How to send a new direct message to the specified user from the authenticating user (TWITTER).

Resource URL


Step 1:  Download Twiiter API class file and placed inside the  third_party or vendor.


Step 2: Go to Twitter developer site create new app https://dev.twitter.com/apps

Step 3: After creating application get a keys Consumer key and consumer secret key like.


Step 4:  In View use directly php page 

keys are Consumer key , consumer secret key , oauth_access_token and oauth_access_token_secret keys placed inside PHP page.

<?php
/* call TwitterAPI.php class APPPATH (or) dir path*/
require_once( APPPATH .'TwitterAPI.php');
/** Set access tokens here - see: https://dev.twitter.com/apps/ **/
$settings = array(
'oauth_access_token' => "2207803*16-71s9C6iVrSxwTxQgtEt8AhwZNa3pWY",
'oauth_access_token_secret' => "70PEshd9877sdgsdgNcJhlYb25Zl4hlOWHvGQVw",
'consumer_key' => "VIAiEsdgasdg46rH2Q",
'consumer_secret' => "eXktHzHKK3634fhgdsahf67346uKbNkJRjdNTjiV9uxVXRA"
);
$url = 'https://api.twitter.com/1.1/direct_messages/new.json';
$requestMethod = 'POST';
//https://api.twitter.com/1/direct_messages/new.format
$postfields = array(
'user_id' => 'TypeTwitterUserId',
'text' => 'Hi this is suneelkumar.'
);
/* Calling TwiiterAPI class */
$twitter = new TwitterAPIExchange($settings);
echo $twitter->buildOauth($url, $requestMethod)
->setPostfields($postfields)
->performRequest();
?>