Post your tweet from twitter api and php

March 11, 2010 at 7:13 pm 2 comments

Twitter is the new social media sensational and many application developers want to add twitter with their site. Many times application developers want to send their updates,users comment and other information to twitter from their application. Twitter provides API to use its services.

Here I give you a very simple function that can post your tweet from your application to twitter. This uses cURL.

function postToTwitter($twitterusername,$twitterpassword,$tweet)
{
$host = “http://twitter.com/statuses/update.xml?status=”.urlencode(stripslashes(urldecode($tweet)));

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $host);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERPWD, “$twitterusername:$twitterpassword”);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_POST, 1);

$result = curl_exec($ch);
// Look at the returned header
$resultArray = curl_getinfo($ch);

curl_close($ch);

if($resultArray['http_code'] == “200″)
{

$status=true;
}
else {

$status=false;

}
return $status;
}

This function posts your tweet successfully with the signature API on twitter.

Advertisement

Entry filed under: API, Uncategorized. Tags: , , , , .

Submit Sitemap Dynamically In Search Engines Testing!

2 Comments Add your own

  • 1. CCTV Installation  |  March 3, 2011 at 12:24 am

    Wow many thanks. This is very useful post. Can it be done in JSP as well as PHP? Which is easier?

    Reply
  • 2. hau_pan  |  July 22, 2011 at 9:51 am

    gghggggg

    Reply

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 )

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed



Follow

Get every new post delivered to your Inbox.