Skip to content

Instantly share code, notes, and snippets.

@lamprosg
Created July 19, 2012 09:25
Show Gist options
  • Select an option

  • Save lamprosg/3142647 to your computer and use it in GitHub Desktop.

Select an option

Save lamprosg/3142647 to your computer and use it in GitHub Desktop.
Simple post message to twitter with PHP
<?php
$url = 'http://twitter.com/statuses/update.xml';
$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);
if (empty($buffer)) {
echo "Error. Please check your username/password!";
} else {
echo "Posted";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment