fumbler Posted November 7, 2008 Share Posted November 7, 2008 I found the following snippet today. I'm new to PHP and am trying to use this snippet to add a text area to a page on my site that posts to Twitter whatever I enter into the text area. This code seems perfect and it works, but lacks the actual html text area where I would enter the text to post. (instead it just has a default message on the $message = line) Where or how in your opinion would I enter that text area in this code below? <?php // Set username and password $username = 'username'; $password = 'password'; // The message you want to send $message = 'is twittering from php using curl'; // The twitter API address $url = 'http://twitter.com/statuses/update.xml'; // Alternative JSON version // $url = 'http://twitter.com/statuses/update.json'; // Set up and execute the curl process $curl_handle = curl_init(); curl_setopt($curl_handle, CURLOPT_URL, "$url"); 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, "$username:$password"); $buffer = curl_exec($curl_handle); curl_close($curl_handle); // check for success or failure if (empty($buffer)) { echo 'message'; } else { echo 'success'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/131724-posting-to-twitter-using-php-snippet/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.