Naftuli Kay
Naftuli Kay

Reputation: 91630

How do I authenticate my Python application with Google for the Google Contacts API?

I'm building an application which uses the Python gdata library to access Google Contacts and I need to authenticate via that library in order to make my requests work. I'm kind of new to this, but basically I'm building a service that runs on a cron job to pull contacts from Google in order to back them up to a local database.

How do I trigger the authentication before I run get_contacts() on the gdata.contacts.client.ContactsClient object? Is there a way I can display either a WebKit browser or use the default browser to authenticate the application? Other than the authentication, it'll be a command line application which will run in the background. How do I do this?

Upvotes: 0

Views: 398

Answers (1)

NeilMonday
NeilMonday

Reputation: 2730

This is for Google Docs, but i think the practice is the same?

import gdata.docs.service

# Create a client class which will make HTTP requests with Google Docs server.
client = gdata.docs.service.DocsService()
# Authenticate using your Google Docs email address and password.
client.ClientLogin('[email protected]', 'password')

# Query the server for an Atom feed containing a list of your documents.
documents_feed = client.GetDocumentListFeed()
# Loop through the feed and extract each document entry.
for document_entry in documents_feed.entry:
  # Display the title of the document on the command line.
  print document_entry.title.text

More info: http://code.google.com/apis/gdata/articles/python_client_lib.html

Upvotes: 1

Related Questions