Skip to content

Instantly share code, notes, and snippets.

@solon
Created July 19, 2010 06:26
Show Gist options
  • Save solon/481067 to your computer and use it in GitHub Desktop.
Save solon/481067 to your computer and use it in GitHub Desktop.
<?php
/*
* sendTweet.php
*
* To send a tweet, request the URL of this script with a status parameter like this:
* http://localhost/sendTweet.php?status=this is a test tweet
*/
$status = $_GET['status'];
$username = "YOUR_TWITTER_USERNAME";
$password = "YOUR_PASSWORD";
$twitterUrl = "http://api.twitter.com/1/statuses/update.json?status=" . urlencode($status);
$curl;
$curl = curl_init();
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_USERPWD, "$username:$password");
curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($curl, CURLOPT_URL, $twitterUrl);
$result = curl_exec($curl);
curl_close($curl);
header('Content-Type: application/json');
print $result;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment