Serotonin Storm

About

The opensource blog of Justin Quick discussing software/web development, security, and general techie goodness. read more...

Subscribe

Categories

Recent Posts

Hacking Away at Voices in The Ether

The emerging concept of a Google Voice API
Sept. 16, 2009
Google, Python, Web,

This is the story of implementing Google Voice functionality in Python

Let me start this off by saying that there is no official API for Google Voice. Voice was a product developed by GrandCentral and then subsequently bought out by Google. The tricky part about this transfer was the terms of service which Google has adapted and modified. In Google's ToS (which they inherited from GrandCentral) they outline the service for personal, non-commercial use only.

GRANT OF RIGHTS TO USE SERVICES. Effective upon acceptance of this Agreement, Google Voice hereby grants to Subscriber a personal, nonexclusive, nontransferable, revocable license to access and use the Services (as defined below), for Subscriber's non-commercial use.

This probably means that Google is not going to get around to making an API anytime soon. Not feeling like waiting around for Google, it was time to hack at it.

The interesting thing about Voice is that it uses a very particular API for its web interface, but Google has yet to publish documentation anywhere for it. The web app just makes a series of authenticated HTTPS requests to the Voice server, which allows it to place calls, send sms messages, and most of the communication is done with xml. I say most because the standard data format is wrapped in an ugly XML envelope. Here is what a typical response looks like

<?xml version="1.0" encoding="UTF-8"?>
<response>
  <json><![CDATA[{"messages":{"3b8d9d77...]]></json>
  <html><![CDATA[
    <div id="3b8d9d77..."
         class="goog-flat-button gc-message gc-message-read">
    <div class="gc-message-bg">
    ...      
    ]]></html>
</response>

Notice that there are both JSON and HTML payloads contained inside the XML envelope, which have to be parsed separately. Parsing the JSON in Python2.5 is easy with simplejson and natively in Python>=2.6 with the json module. The data contained in that section has only a portion of the interesting data, which makes full data retrieval a royal pain in the ass. The rest of the good stuff is stored awkwardly in the HTML payload, and contains such niceties as sms message text, voicemail/call transcription, and caller thumbnails.

Even without the commercial issues, there is an interesting social networking application that would allow you to broadcast a quick call/message to a local group of friends, like "hey! let's get together". The API would be useful even for interesting non-commercial social networking use. Hopefully in the future, regardless of API, there will be a whole generation of apps that will find a way to use this functionality. To that effect, PyGoogleVoice has appeared on the scene. It currently allows you to place calls, send sms, download voicemails/recorded messages, and search the various folders of your Google Voice Accounts. Here is some example usage

from googlevoice import Voice
voice = Voice()
voice.login('myusername@gmail.com','mypassword')
voice.call('18004664411', '14075551234')

And it can be extended to other platforms as well. Someone has already found a way to have the service interact with Asterisk to create a really sweet PBX setup.

The lack of a solidified API from Google means that they are free to change things around at will.






blog comments powered by Disqus