posting direct message to Twitter

i am basically trying to retrieve the response of a chatbot from mysql database with query below. As i run script i don’t get any error from the server but it seems the post doesn’t take $data2 which is an array that includes the keys “user_id” and “text” that are normally accepted (eg: $dmessage->post(‘direct_messages/new/wrap_links=true’, ‘text’->‘example’, ‘12345’);`

As result of the above i can’t post to Twitter the chatobot response as the recipient (my other twitter account used for testing) doesn’t get the answer…

[php]

include_once (‘connect.php’);

connect_to_database();

$query2 = mysql_query (“SELECT response FROM conversation_log WHERE id = (SELECT MAX(id) FROM conversation_log)”) or die (mysql_error());

$row = mysql_fetch_row($query2);

$response = $row[0];

//this is the array with the parameters to be used to send bot responses via Twitter API. It normally takes
$data2 = array(“text”=>"$response" , “user_id”=> “$userid”);

//this modifies the array values with response e userid fields
$data2[“text”] = “$response”;
$data2[“user_id”] = “$userid”;

require_once(‘config_oauth.php’); // includes the applications Oauth keys

require_once($_SERVER[‘DOCUMENT_ROOT’].‘Program-O/gui/xml/oauth/twitteroauth.php’); //Full path to twitteroauth.php library

$dmessage = new TwitterOAuth($consumer_key,$consumer_secret, $oAuthToken, $oAuthSecret); // create new instance with the credentials

//sends the bot response via Twitter API by going through the array $data2
$dmessage->post(‘direct_messages/new/wrap_links=true’, $data2);

[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service