Posted: Tue Jan 17, 2006 6:38 pm Post subject: [PHP-Tutorial] Show your Google Talk status on your website
Start
I'm gonna show you how to get your own Google Talk status on your webpage. Thanks to fantawttw for his Online Status application that we will use. My english isn't good, so you can post if I've spelled anything wrong.
Step 1: Add jabberonlinestatus [at] jabber.org (old: gtalkonlinestatus [at] googlemail.com) to your contact list.
After the bot accept you as a friend (can take up to 5 seconds), send a message with the text
Quote:
ENCSTRING
He will answer you with this text where (enc) is your own encrypted string.
Save the text that replaces (enc) somewhere (maybe on a paper, maybe in a notepad-document) because we'll use it soon.
Step 2: Open your PHP-site in your editor, find a place in your HTML-code where you want to show the text. We'll use the file-function (follows PHP5). Then copy & paste this code:
Code:
<?php
// Set your enc-string between the quotes
$enc = "";
// Put the url together
$url = 'http://www.jonburrows.co.uk/gtalkstatus/6/' . $enc . '.jpg';
// Save the site as a array of lines
$lines = file($url);
// Loop through all lines
foreach($lines as $line){
// Looks if it returns 1 that means that you are available
if($line == 1){
echo "I'm available at Google Talk";
}
// Else you are not available
else{
echo "I'm not available at Google Talk";
}
}
?>
And write your (enc) text that you saved between the quotes. Now you can see if you are available or not available. Available means Online, Busy, Idle, and unavailable means offline. Now if you want you can show different images depending on if you are available or not. Its easy just change "I'm available at Google Talk" to "<IMG SRC="myimage.gif">" and "I'm not available at Google Talk" to "<IMG SRC="myimage2.gif">".
Step 3: It wasn't funny enough with just showing if you are available or not, so I'm going to show your current status. Its just small changes. Here is the code:
Code:
<?php
// Set your enc-string between the quotes
$enc = "";
// Put the url together
$url = 'http://www.jonburrows.co.uk/gtalkstatus/7/' . $enc . '.jpg';
// Save the site as a array of lines
$lines = file($url);
// Loop through all lines
foreach($lines as $line){
// Print the text that Gtalkstatus gives us
echo $line;
}
?>
Step 4: Now we're going to look if we are Idle, Available, Busy, Offline, Chatty (like available) and xa (extended idle). Chatty and xa isn't available in the current version of Google Talk but its supported in the protocol XMPP, like bots can have that status and you can maybe have it with a another Google Talk Client. Every status have a number that Gtalkstatus returns when you request the site. Here's the list:
1 = Available
2 = Busy
3 = Idle
4 = Chatty
5 = xa
0 and else = Unavailable
Code:
<?php
// Set your enc-string between the quotes
$enc = "";
// Put the url together
$url = 'http://www.jonburrows.co.uk/gtalkstatus/8/' . $enc . '.jpg';
// Save the site as a array of lines
$lines = file($url);
// Loop through all lines
foreach($lines as $line){
// Check what number Gtalkstatus returns
if($line == "1"){
echo "I'm available";
}
elseif($line == "2"){
echo "I'm busy";
}
elseif($line == "3"){
echo "I'm idle";
}
elseif($line == "4"){
echo "I'm chatty";
}
elseif($line == "5"){
echo "I'm idle extended";
}
else{
echo "I'm unavailable";
}
}
?>
Edit 1: You can change this (because Google Talk shows xa as idle and chatty as available) :
Thats all I hope this has been useful, you can open for example http://www.google.com/ with the file()-command and replace Google with your name or something fun . For more advanced HTTP-Get functions use cURL and libcurl. libcurl is supported by the most programming languages (ex. VB, C++, and .NET).
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum