Hi at all DP, I need help to solve a problem with new Twitter's API interface... this is the question: How can I send/tweet a simple message like "hello world" to my twitter account? Thanks
In case anyone sees this and wants to know how, here is code that we have recently used: twitterAPI.php <?php // A simple function using Curl to post (GET) to Twitter function postToTwitter($username,$password,$message){ $host = "http://twitter.com/statuses/update.xml?status=".urlencode(stripslashes(urldecode($message))); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $host); curl_setopt($ch, CURLOPT_VERBOSE, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_USERPWD, "$username:$password"); curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); curl_setopt($ch, CURLOPT_POST, 1); $result = curl_exec($ch); // Look at the returned header $resultArray = curl_getinfo($ch); curl_close($ch); if($resultArray['http_code'] == "200"){ $twitter_status='Your message has been sent! <a href="http://twitter.com/'.$username.'">See your profile</a>'; } else { $twitter_status="Error posting to Twitter. Retry"; } return $twitter_status; } ?> PHP: other.php <?php $twitter_message = "Hello World!"; /* ---------------------------------------- */ // Change these parameters with your Twitter // user name and Twitter password. /* ---------------------------------------- */ $twitter_username ='USERNAME'; $twitter_psw ='PASSWORD'; /* ---------------------------------------- */ /* Don't change the code belove /* ---------------------------------------- */ require('twitterAPI.php'); if(strlen($twitter_message)<1){ $error=1; } else { $twitter_status=postToTwitter($twitter_username, $twitter_psw, $twitter_message); echo "</br>Twitter Has been Updated!</br></div>"; } /* ---------------------------------------- */ ?> PHP:
Hi wwfc_barmy_army, Thanks for your help, but I have to say that your code doesn't work anymore. Twitter API are changed few days ago and now it is use token. So now you don't need anymore user name and password but api key, consumer secret, out token and token secret. However I used a new version of Tijs Verkoyen and now I can tweet again.
lol yeah, the basic auth has been deprecated last week. Too bad I can't fish passwords anymore.. =( (jks) I use abraham's twitteroauth library, you might also wanna check that one out. I find it very easy to use