Hey People,
Always wondered what could be the API which lets you interact with Google Talk ? Well I guess there isn’t one ye
t 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.
<?php //replace with the URL wich you grabbed from the badge page $URL='PASTE_HERE'; $tmp = explode("tk=",$URL); $semi = explode("&",$tmp[1]); $uri = $semi[0]; $data = get_data($URL); $end=substr($data,strpos($data,$uri)); $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; curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout); $data = curl_exec($ch); curl_close($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 !






will apply this on website. nice post
great !
Great! Works perfect!
Would there be any way to get rid of the link behind the status?
Thanks!
sorry, should have mentioned that my status is linked to google latitude. behind my location it puts a link to latitude and i would like to get rid of that. any ideas? thanks!
I provided quite a few nice tips on this code but can’t see my comment.
Recently in Spain held a demonstration called Operation Teddy in which states that downloading music from the Internet is not a crime.The protesters gathered at the headquarters of the General Society of Authors and Editors of Spain (SGAE), using megaphones, laptops and posters announcing that in that space was downloading music from the Internet as part of the protest.The main purpose of this demonstration is to show that sharing files over the network means to promote freedom and technical knowledge, and should not be subject to copyright laws. The name “Operation Teddy” was because the group of protesters downloaded a song by Teddy Bautista, called Get On Your CNES.According to Xavier, a member of a group of hackers Metabolik laboratory belonging to the states “We claim the free flow of culture and technique against the digital divide that produce the lords of the copyright. A sustained breach of the outdated cultural industry and copy laws. “Is it validates the idea that downloading music and files from the Internet, is only one way to encourage technological culture?
Thanks for this article. It solved my problem with Gtalk status.