Shortest piece of php code to update twitter status

There are huge resources of php to update twitter status using API. But a few days back i found a very small piece of php code to update twitter status which uses stream. Here are the code –

  $context = stream_context_create(array(
    'http' => array(
	  'method'  => 'POST',	
      'header'  => sprintf("Authorization: Basic %s\r\n", base64_encode("$username:$password")).
                   "Content-type: application/x-www-form-urlencoded\r\n",
      'content' => http_build_query(array('status' => $message)),
	  'timeout' => 5, 
    ),
  ));
  
  $ret = file_get_contents('http://twitter.com/statuses/update.xml', false, $context);

Put username, password, message as needed. I think this is the php shortest code ever to update twitter status. Enjoy!

About these ads

2 thoughts on “Shortest piece of php code to update twitter status

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s