{ by david linsin }

March 17, 2007

Integrating Twitter and plazes

Today I integrated Twitter and plazes into my blog, you can see it on the "presence" box at the sidebar. Integrating Twitter is pretty straightforward, since they are providing a javascript snippet that you can simply drop into your html code.

<script type="text/javascript">
function twitterCallback(obj) {
var id = obj[0].user.id;
document.getElementById('my_twitter_status').innerHTML = obj[0].text;
document.getElementById('my_twitter_status_time').innerHTML = obj[0].relative_created_at;
<span id="my_twitter_status"></span> <span id="my_twitter_status_time"></span>

<script type="text/javascript" src="http://www.twitter.com/t/status/user_timeline/

Integrating plazes is not so simple though, at least if you want to do it text-based, without any flash widget. They provide an API, which you can only use after you registered a developer key, which I did. Unfortunately the developer key is not working, so I'm still waiting for support to get back to me. In the mean time I adopted a wordpress-plugin that was written by Tijs Teulings. The plazes API is based on XMLRPC. I think that makes integration via javascript quite messy, so I decided to use a php indirection which handles all the XMLRPC stuff for me.

$location = askPlazes($plazes_username, $plazes_password_hash);

if ($location['plazecity'] == "o" || $location['plazecity'] == "o" || $location['plazename'] == "o") {
echo $_GET['callback'] . "(null);";
} else {
echo $_GET['callback'] . "({ \"plazes\": { \"city\": \"" . $location['plazecity'] . "\", \"name\": \"". $location['plazename'] . "\", \"url\": \"". $location['plazeurl'] . "\" } });";

function askPlazes($username, $passwordMD5) {
$c=new xmlrpc_client("/xmlrpc/whereami.php", "beta.plazes.com", 80);
$params = array(new xmlrpcval($username, "string"), new xmlrpcval($passwordMD5, "string"));
$f = new xmlrpcmsg('plazes.whereami', $params);
$r = $c->send($f);
$v = $r->value();

if ($r->faultCode()) {
echo "Plazes XML-RPC Fault: ";
echo "Code: " . $r->faultCode() . " Reason '" .$r->faultString()."'";
} else {
$PlazesData = php_xmlrpc_decode($v);
return $PlazesData;

It uses a xmlrpc library to make a call to a deprecated plazes API called "whereami". The call basically returns your current plaze with all necessary information. For javascript integration the php script prints a function call, which is provided as parameter when calling the script. To integrate this into my blog, I simply had to drop in a javascript snippet which includes the call to the php script and an implemention of the callback method.

function plazes(obj) {
if (obj != null) {
document.getElementById('my_plazes_city').innerHTML = 'doing that in ' + obj.plazes.city;

document.getElementById('my_plazes_name').innerHTML = ' at ' + obj.plazes.name + '';
} else {
document.getElementById('my_plazes_city').innerHTML = 'offline';

<script src="http://area51.linsin.de/plazes.php?callback=plazes" type="text/javascript"></script>

I've already implemented the php script to call the current plazes API, but as mentioned before I'm still waiting for response of the support.



  • mail(dlinsin@gmail.com)
  • jabber(dlinsin@gmail.com)
  • skype(dlinsin)