GOTO

Wednesday, May 12, 2010

Updating your Twitter status from your application/site

Hi everybody,

I'm developing a website using Joomla for my university about the world of work. A website like that is frequently updated and must also have a Facebook page, a Gtalk account and a Twitter profile for extending its communicability . How can we use these two social networks? Well, we can post events, news and communications taken from our website, but it's a very long and boring work to do manually. So we must automatize this process with an application (in this case a web application written in PHP). Let's start talking about how to update Twitter status..Twitter offers many APIs to developers ( for further information visit http://apiwiki.twitter.com/ ) for authenticating,reading updates, posting messages, responding...So you can make all what you want but without using Twitter. Ok, we are only interested in posting message, so the API we are interested in is http://twitter.com/statuses/update.json. See an example:
$out = "POST http://twitter.com/statuses/update.json HTTP/1.1\r\n"
."Host: twitter.com\r\n"
."Authorization: Basic ".base64_encode ('user_name:user_password')."\r\n"
."Content-type: application/x-www-form-urlencoded\r\n"
."Content-length: ".strlen ("status=$msg")."\r\n"
."Connection: Close\r\n\r\n"
."status=$msg";

$fp = fsockopen ('twitter.com', 80);
fwrite ($fp, $out);
fclose ($fp);
Remember to change user_name:user_password with its real value (':' character is required) and set $msg with data taken from your data source (files, databases...).
You can also call this API using curl by your command line, so you can integrate Twitter functionalities in your applications:
curl -u 'user_name:user_password' -d status="Testing twitter API by console" http://twitter.com/statuses/update.xml
Once updated twitter status, you can update Facebook and Buzz statuses too, installing an application for Facebook for reading your status on Twitter (I suggest you use smart twitter) and adding a reference in Buzz to your Twitter profile.

Data source ---> API elaboration ---> Twitter ---> Facebook and Buzz.

::See you next post::

No comments:

Post a Comment