Skip to content

Instantly share code, notes, and snippets.

@ninadsp
Created July 28, 2013 14:45
Show Gist options
  • Save ninadsp/6098838 to your computer and use it in GitHub Desktop.
Save ninadsp/6098838 to your computer and use it in GitHub Desktop.
Code snippet from my blogpost How to Tweet using PHP (http://ninad.pundaliks.in/blog/2009/08/how-to-tweet-using-your-own-php-script-2/). Deprecated code, depended on Twitter API v1 and Basic Authentication. Will not work anymore
<?php
if($_REQUEST['ajax_req']== true)
{
//Process the tweet
$username = $_REQUEST['username'];
$password = $_REQUEST['password'];
$status = $_REQUEST['status'];
$auth_string = $username.":".$password;
$postdata = array('status' => $status );
$options = array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $postdata,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_URL => 'https://twitter.com/statuses/update.json',
CURLOPT_USERPWD => $auth_string
);
$ch = curl_init();
curl_setopt_array($ch, $options);
$data = curl_exec($ch);
curl_close($ch);
Header('Type: application/json')
die($data);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment