Hey People,

Always wondered what could be the API which lets you interact with Google Talk ? Well I guess there isn’t one yet other than just creating bots. But what if you want to show the current Google Talk or GTalk status on your website or want it to use somewhere else like updating on twitter as well ?

Well in that case all you can do is just trick Google with its own tool. For this example we are going to use Google’s talkback badge. Please note that Google doesnt provide any authentic way or API to grab Gtalk’s status. This is a trick which grabs your latest status from the source of the Google badge( I know that sounds spooky ). We are going to use cURL, and other string function in PHP.

All you have to do is to repeat the following steps carefully !

Step 1 :

Grab the badge code by visiting the Google badge page. Make sure you check the “Show your status message” option, otherwise it will only show Available/Not Available.

Step 2 :

Now copy the embed code from the textarea and paste it in notepad. Analyze the embed code closely and copy the source of the iframe mentioned in the script tag. Look below to see example.

<iframe src=”GRAB_THIS_PART_OF_THE_CODE” allowtransparency="true" frameborder="0" height="60" width="200"></iframe>

Or if you can paste this code into Microsoft Word, then you have to copy the portion which gets underlined or link from the above code.

Step 3 :

Paste the URL in the following script (line #3), which you just copied in the Step 2.

//replace with the URL wich you grabbed from the badge page
$tmp = explode("tk=",$URL);
$semi = explode("&amp;",$tmp[1]);
$uri = $semi[0];
$data = get_data($URL);
$tmp = trim(strip_tags(substr($end,21)));
echo $status_message = substr($tmp,strpos($tmp,"\n"));
/* grabs the data from the URL */
function get_data($url)
  $ch = curl_init();
  $timeout = 5;
  $data = curl_exec($ch);
  return $data;

This method is not always fool proof, but I have tested this script many times and with different status messages. There are many scripts available online which use the same badge code to get the status message. But most of them use fopen function of PHP which is not supported on most of the servers. However the above script uses cURL to get the data from the URL, so its more robust than other scripts.

Hope you enjoyed this post.

Stay Digified !!
Sachin Khosla !

Share this post: