I was using the following code to hook to my twitter account but now since I was using basic authentication instead of OAuth I am not tweeting anymore. Does anyone know of the code of samples that use OAuth with cURL/PHP?
<? function make_jmp_url($url,$login,$appkey,$format = 'xml',$version = '2.0.1') { //create the URL $jmp = 'http://api.j.mp/shorten?version='. $version.'&longUrl='.urlencode($url).'&login='.$login.'&apiKey='. $appkey.'&format='.$format; //get the url $response = file_get_contents($jmp); //parse depending on desired format if(strtolower($format) == 'json') { $json = @json_decode($response,true); return $json['results'][$url]['shortUrl']; } else //xml { $xml = simplexml_load_string($response); return 'http://j.mp/'.$xml->results->nodeKeyVal->hash; } } function tweet($status) { $username = 'test'; $password = 'test'; if ($status) { $tweetUrl = 'http://www.twitter.com/statuses/update.xml'; $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, "$tweetUrl"); curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 2); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, "status=$status"); curl_setopt($curl, CURLOPT_USERPWD, "$username:$password"); $result = curl_exec($curl); $resultArray = curl_getinfo($curl); if ($resultArray['http_code'] == 200) { $msg += ' and was Tweeted!'; } curl_close($curl); } } $tweet = ''; $longURL = 'http://test.com' . $row->id; $shortURL = make_jmp_url($longURL, 'username', 'apikey', 'json'); $tweet .= urlencode( $row->title ); if (strlen($tweet) > 119) { // shorten status update to fit in 140 with URL $tweet = substr($tweet, 0, 116 ) . '...'; } $tweet .= ' - '; $tweet .= $shortURL; tweet($tweet); ?> -- Twitter developer documentation and resources: http://dev.twitter.com/doc API updates via Twitter: http://twitter.com/twitterapi Issues/Enhancements Tracker: http://code.google.com/p/twitter-api/issues/list Change your membership to this group: http://groups.google.com/group/twitter-development-talk