I have a page with a textbox and a button, I want to post to twitter the contents of the textbox.
I have created an app on dev.twitter, I first check if the user is authenticated or not, then I add the following to the button’s click event :
//sending message
$.post('postStatus.php',{
status:message
},function(response){
$("#debug").html(response);
});
The file postStatus.php is (first draft) :
<?php
require_once 'EpiCurl.php';
require_once 'EpiOAuth.php';
require_once 'EpiTwitter.php';
require_once 'secret.php';
//is connected ?
/*
$twitterObj = new EpiTwitter($consumerKey, $consumerSecret);
$oauth_token = @$_GET['oauth_token'];
if($oauth_token == '')
die();
*/
//validate message
$message=@$_POST['status'];
$message = trim($message);
if ($message === '')
die();
//send
$twitterObj->setToken($_COOKIE['oauth_token'],$_COOKIE['oauth_token_secret']);
$status=$twitterObj->post_statusesUpdate(array('status' => $message));
$status->response;
echo 'Your status has been updated';
Am I missing something in the validation of $message ? What should I, if anything, enclose in try/catch blocks ? And finally, should I have postStatus.php return a 500 error, or is die() ok ?
In your PHP
$consumerKeyand$consumerSecretaren’t defined +$_GET['oauth_token']will never be set because the url in your js is static.Also you might want to escape the status before you attpemt to post it.