Monday, April 09, 2007

Grabbing your Google Bookmarks in Python

Going to be using this to display my bookmarks as links on my site but... This authenticates and pulls the rss of my google booksmarks. Can also be used with Google Search History.

Authenticating to Gdata (ex picasa web) in Python

So until the python gdata library has picasa web support, the following is a way to authenticate with your google account (for say posting pictures to picasa web. This method is not needed for private albums, you can use the album's authkey instead and save yourself an extra http request)

To start off we'll need some libraries, the login credentials, and the url of a private album (for testing)


Next we'll define the function that does the authentication. This has the url to authenticate against and the header information. Most of this function is generic depending on which Google service you are connecting to.



The next part, the request, can differ depending on service. The service for picasa web is "lh2"


Then return if we have successfully authenticated


To use this we must get an httplib2 object and try to authenticate


Then we can test to see if we have authenticated, and grab the private data


Just in case we are fed redirects, we would want to test for these


then we would have the data stored in response. We could also print out an error if we were unable to login




Reference