In case you’re just here for the script and aren’t interested in reading the story of how this project came to be, click here.
The Story
I have a friend who doesn’t use social networks, but he updates his Google Talk status prolifically. Recently, we joked about it being his microblogging. Then I started to ask myself if there was a way this microblogging could be broadcasted to other outlets. My first thought was of Twitter specifically, so I set off on a Google Search of how to make this work.
Not surprisingly, other people have wanted to do this same thing. The first stop was at Coactlab to check out their service. Coactlab pings a service called Jabberland for your Google Talk status and then relays that information back to Twitter. However, there were two big problems with this. The first problem is that the script for download on the site uses a defunct method of authenticating for Twitter (Twitter has moved to OAuth instead of just a username/password combination). The second problem, even bigger than OAuth, was that Jabberland doesn’t appear to work anymore. So after an hour or so of playing on the site and realizing that things weren’t going to work with a Jabberland script, I moved on to see what else I could find.
And I found a couple interesting leads in the comments of Coactlab’s post. The first lead was written by Jon Deutsch who noted that something called a Google Talk chatback badge existed and broadcasted your Google Talk status in HTML. The second lead was a link to Dan’s Horrendous Waste of Bandwidth. On this site, Dan Ray created a service that, as he describes it, has “taken (Coactlab’s) code and hacked it into a multi-user database-backed web service that anyone can sign up for.” This seemed like a great idea, so I went to Dan’s site and registered for the service. After a short round of testing though, I realized something wasn’t working anymore and suspected his program was pinging the now-defunct Jabberland for a user’s status.
I sent an email to Dan and he was nice enough to share his script with me. Indeed, it was looking for a chat status at Jabberland and still used the old authentication method, but the code got me off to a good start on writing an alternative. This project is deeply indebted to him, his script, and his many replies to my inane questions about PHP, scripting, and authenticating.
In the span of 72 hours, I came up with something that pings your Google Talk chatback badge (intended to be embedded on websites so visitor can chat with you over Gtalk) for your status and then returns that status to your Twitter account. The script is updated for current OAuth authentication on Twitter and should work with any login for an active user. I got the OAuth and OAuth for Twitter scripts from Abraham Williams‘s github page. They made my first entry into PHP/OAuth programming quite painless, and I recommend using them for anyone working on this project.
This project is ugly at best right now. It also shows how little PHP I was able to learn in 72 hours, although it does work in my own limited tests. I’m posting it in hopes of helping others out with posting Google Talk statuses to Twitter. I am also hoping some users can clear up bugs and code along the way and let me know what they’ve changed so I can make updates to this post. Let me know in the comments either way.
The Script
Click here to download the files necessary. Included in the .zip file here is the PHP script for broadcasting a Google Talk status to Twitter as well as the two necessary OAuth PHP files. To use these, you will first have to make a few modifications to the gtalk2twitter.php script:
- Go to the Twitter dev site and register your application. You’ll need a name, description, and URL to start.
- Once you’re on your application’s webpage, go to Settings and make sure to change your Application Type from “Read only” to “Read and write.” Click Update and return to your Details page.
- Copy your consumer key and consumer secret. We’ll need these in a couple of steps.
- Click the button “Create my access token.” Copy the access token and access token secret.
- Enter your consumer key, consumer secret, OAuth/access token, and OAuth/access token secret in the designated places.
- Get the URL for your Google Talk chatback badge. You can get your badge by signing into your Google account and clicking here. Once on the Google Talk chatback badge page, click on edit and make sure to check the “show your status” box. If you don’t, this script won’t work.
- Now copy the chatback URL in the box at the bottom of the page. Copy everything inside the quotation marks, from http to h=60. Once you’ve done this, enter the URL in the designated place in the script.
- Finally, make note of the name used in your chatback badge on the chatback page. You will see what name is being used for you in the sample badge with the text “Chat with YourName.” Copy YourName exactly as it shows in the badge and paste it into the designated place in the script.
You’re done editing the script! Now place the script in the same folder as OAuth.php and twitteroauth.php (or modify it accordingly) and run it with cron, launchd, or some similar service every 5 minutes or so. The script won’t post the statuses “Available,” “Offline,” “Busy,” or “Away,” but the hack for this is ugly and could stand to be re-written because it will also remove those words if they’re used in a status saying something else.