Jump to content

posting arrays


sdiegolo78

Recommended Posts

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) doesn't get the answer...what do you think?

 


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);

Link to comment
Share on other sites

The variable $userid has a value? From where it came?

 

And why you set the values two times?

 

$data2 = array("text"=>"$response" , "user_id"=> "$userid");

 

$data2["text"] = "$response";

$data2["user_id"] = "$userid";

 

You dont need to use the " too.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.