Dec 10, 2009

access google contacts through python using google apis

An address book completely online, it can be accessed from net from mobile, from netbook, pdas...gud idea right !!. well here comes google's address book APIs. There is no argument that google's address book is the best online address book.
So lets go to live with it.... ( 1 hrs )
Google contact APIs are available for python, java, javaScript,... But to explain I think python is best as it is very simple.
Requirements : Google contact APIs for python ( google it to download ), Python 2.x( mine is 2.6 ), my operating system is ubuntu. PS: Net connection is a must.
Here as I am using Linux, the explenation is based on linux.
First set the path to the apis. For that, first untar the tar file to some place. Inside that there are two folders atom and gdata. set python path to that folders as follows.
Open a terminal and type,
PYTHONPATH=$PYTHONPATH:/folder/folder/.../ folder/gdata/
okie then enter into python. type python2.6 in terminal ( or python2.x, x is your version, type python and press "tab" ). Then do the following scripts.
import atom
import gdata.contacts
import gdata.contacts.service
gd_client = gdata.contacts.service.ContactsService()
gd_client.email = 'yourmail@gmail.com'
gd_client.password = 'yourpassword'
gd_client.ProgrammaticLogin()

feed = gd_client.GetContactsFeed()

for i, entry in enumerate(feed.entry):
print '\n%s %s' % (i+1, entry.title.text)
if entry.content:
print ' %s' % (entry.content.text)
for email in entry.email:
if email.primary and email.primary == 'true':
print ' %s' % (email.address)

You can write it into a name.py file and run with python command or write each line one by one in python command line. Okie, you got your contacts. This is just for testing google Contact APIs. The APIs provides all the main functions like new, update, retrive,etc..
So the real code we can try in java and j2me as j2me is used for mobile, pdas and java is good for netbooks, touch pads etc.. So it is like a single contact book.
In mobile speed will not be a big problem as one contact set size will go only to some few bytes ( some 50, 60 bytes ). And even if GPRS is as slow as 1kbps( ie 1000bits = 125 bytes ). So it will load in a half second. It is more fast than mobile address book. mmmmm.... really the juice is worth the squeeze.

For Web Developer

  open -a "Google Chrome" --args --disable-web-security