GData Contacts Example


/ Published in: Python
Save to your folder(s)

Simple example of using Google's API for contacts to display the contact name and phone number. More info in the comments.


Copy this code and paste it in your HTML
  1. import sha
  2. import atom
  3. import gdata.contacts
  4. import gdata.contacts.service
  5.  
  6. gd_client = gdata.contacts.service.ContactsService()
  7.  
  8. # Change this obviously
  9. gd_client.email = 'EMAIL'
  10. gd_client.password = 'PASSWORD'
  11. gd_client.ProgrammaticLogin()
  12.  
  13. """
  14. This is used like a case statement later on.
  15. It's apparently a slightly slow way to do it but it just seems so elegant to me. I'm not a Pythonista at all though so there may be a more Pythonic way to do it that I'm not aware of.
  16. """
  17. rel_list = {gdata.contacts.REL_WORK: "Work",
  18. gdata.contacts.REL_HOME: "Home",
  19. gdata.contacts.REL_OTHER: "Other",
  20. gdata.contacts.PHONE_MOBILE: "Mobile"}
  21.  
  22. # This is the date used for "updated_min" below.
  23. date = '2009-08-12T00:00:00'
  24.  
  25. query = gdata.contacts.service.ContactsQuery()
  26. query.updated_min = date
  27.  
  28. feed = gd_client.GetContactsFeed(query.ToUri())
  29.  
  30. for contact in feed.entry:
  31. print contact.title.text
  32. for phone in contact.phone_number:
  33. print rel_list[phone.rel] + ": " + phone.text
  34.  
  35. def rel_type(rel):
  36. pass

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.