Google Voice on App Engine
Google voice still doesn't release their official API, but some people already did some job so that we can use Google Voice more conveniently.
Chad Smith made the Google Voice Firefox addon, which is a great tool that you can use it with your Google Voice number and send SMS message without laving your browser. Chad also posted a topic to introduce how to place calls or send SMS using Google Voice via HTTP or XML request.
See: http://posttopic.com/topic/google-voice-add-on-development
According to Chad’s article, before Google release the API, to use Google Voice’s features in a standalone program is also possible. pygooglevoice is one of this kinds of open-source projects: http://code.google.com/p/pygooglevoice/
Scott Hillman also wrote a script with similar functions to use in command line.
http://everydayscripting.blogspot.com/2009/10/python-custom-google-voice-api.html
I tried to use their library/script in my Google App Engine based web application, and then I met a mess of problems.
Firstly, App Engine supply the URL fetch service API to work with HTTP request. Although you can also make HTTP request using urllib, urllib2 or httplib, but actually, all these kinds of routine call will be redirect to urlfetch API. But URL fetch service has a lot of limitation; it doesn’t handle the Cookies, so that you can't login to Google account in the background before send HTTP request to Google Voice.
Scott did a helper class to handle the Cookies and resolved the login issue.
http://everydayscripting.blogspot.com/2009/08/google-app-engine-cookie-handling-with.html
When I used his URLOpener class to login Google account in my program, I met the exception of "Stripped prohibited headers from URLFetch request: ['Host']". As Google does some restriction in the latest version of App Engine, some HTTP request headers will be recognized as distrustful. So I recommend you to delete the ‘Host’ parameter from headers in Scott’s class. The URLOpener still work normally after comment the “Host” parameter.
Then, I started to replace the HTTP request API in pygooglevoice with Scott’s URLOpener class, and some other problems arose.
pygooglevoice use ConfigParser to store the configuration properties, ConfigParse is not supported by App Engine, so you need to refactor this class. I changed the Conf class to inherit from appengine’s db.Model.
You may meet the encode problem when using pygooglevoice to send SMS message. I fixed the issue by unicode the input text and then encode it to utf-8 standard.
Everything is OK now, you can test the SMS sending feature on my home page: http://cpedia.net/
I will continue to work on a new open-source project, integrate pygooglevoice with all the fixes above together, and demonstrate a sample application on appspot.
Tags: voice, appengine, python, featured
anonymous
Powered by
Recent comments