CWitt Posted March 8, 2009 Share Posted March 8, 2009 I really could use a hand here. I'm working with this Viral Tweet Generator and I want to alter the code so that the HTML form automatically post directly to Twitter. Right now, the php has the form take the visitor's username and password and then posts the message. I would rather have the message just posted on a certain Twitter account that already has the user/pass in the PHP. I would assume it would be as simple as declaring the variable, but my mind seems feeble as I can't figure out why the script won't work. /** * CONFIGURATION SETTINGS * string $message = Message to post on Twitter * string $callingUrl = File the post originated from (or where to return on failure) * string $successUrl = URL to go to on completion **/ $message = "Just reading about this site: it's bonkers!"; $callingUrl = "error.html"; $successUrl = "success.html"; if($_POST['username'] != '' && $_POST['password'] != '') { $result = Twitter::sendTwitter(stripslashes($_POST['username']),stripslashes($_POST['password']),$message); if($result) { header('Location: ' . $successUrl); exit; } } header('Location: ' . $callingUrl); class Twitter { function Twitter() { die('Cannot instantiate this class(Twitter) in: '.__FILE__); } /** * Attempts to contact twitter and post a message * * @param string $uname = Twitter User Name * @param string $pWord = Twitter Password * @param string $message = The message to post through the communication system * @param string $apiUrl = Twitter API Url. (Optional - defaulted to standard XML API) * @return boolean **/ function sendTwitter($uName='',$pWord='',$message='',$apiUrl='http://twitter.com/statuses/update.xml') { $curl_handle = curl_init(); curl_setopt($curl_handle, CURLOPT_URL, "$apiUrl"); curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2); curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl_handle, CURLOPT_POST, 1); curl_setopt($curl_handle, CURLOPT_POSTFIELDS, "status=$message"); curl_setopt($curl_handle, CURLOPT_USERPWD, "$uName:$pWord"); //Attempt to send $buffer = curl_exec($curl_handle); curl_close($curl_handle); if(strpos($buffer,'<error>') !== false) { return false; } else { return true; } } } ?> So essentially, I just want to declare $uname & $pWord and I'll just remove that part of the HTML form. Thanks in advance! Link to comment https://forums.phpfreaks.com/topic/148507-simple-twitter-php/ Share on other sites More sharing options...
CWitt Posted March 8, 2009 Author Share Posted March 8, 2009 I've seemed to notice that 'function sendTwitter' is probably where I need to adjust the variable, any thoughts? Link to comment https://forums.phpfreaks.com/topic/148507-simple-twitter-php/#findComment-779933 Share on other sites More sharing options...
CWitt Posted March 10, 2009 Author Share Posted March 10, 2009 ^ Bump oh Gracious PHP Gods. Link to comment https://forums.phpfreaks.com/topic/148507-simple-twitter-php/#findComment-781695 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.