Google Picasa API Python: Developers Guide

Before you ask… Yes I struggled with the title of this post, but give me a break it’s 4:30 am here! 🙂

I’m currently developing in python for Google App Engine and are using the Picasa API. I found this great guide from Google with exampels: https://developers.google.com/picasa-web/docs/1.0/developers_guide_python It’s far from complete but the examples pushes me in the right direction and then some testing, trial and error gives me a chance to learn even more! So i thought I would share one of the things that got me in to trouble this morning.

I was trying to add a new album to the feed and got this error:

(404, ‘Not Found’, ‘Unknown user.’)

Even though the user is authenticated via oauth. But then i realized that this was the same issue I head before, the users e-mail isn’t in the mix. I needed it for layout purposes before, to display profiles and so on, you can read about that here: Python: Get user info after oauth All the request I have done before, getting feeds of albums, pictures and so on, has been uri input from me in the code. This function just looks like this:

[py]gd_client.InsertAlbum(title=’Test’, summary=’a test album’)[/py]

Where the gd_client is an instance of gdata.photos.service.PhotosService() with the oauth token all-ready specified using the code example from the official Google guide and spiced with the functions from my previous mentioned post. But still it doesn’t work! So I realized that even though it is authorized it has no idea who the user is trying to insert the new album. According to the feed documentation you should do a post like this:
[xml]POST https://picasaweb.google.com/data/feed/api/user/userID

<entry xmlns=’http://www.w3.org/2005/Atom&#8217;
xmlns:media=’http://search.yahoo.com/mrss/&#8217;
xmlns:gphoto=’http://schemas.google.com/photos/2007′&gt;
<title type=’text’>Trip To Italy</title>
<summary type=’text’>This was the recent trip I took to Italy.</summary>
<gphoto:location>Italy</gphoto:location>
<gphoto:access>public</gphoto:access>
<gphoto:timestamp>1152255600000</gphoto:timestamp>
<media:group>
<media:keywords>italy, vacation</media:keywords>
</media:group>
<category scheme=’http://schemas.google.com/g/2005#kind&#8217;
term=’http://schemas.google.com/photos/2007#album’></category&gt;
</entry>[/xml]

So here is what stuff goes wrong. Looking what the gd_client is actually doing is posting to https://picasaweb.google.com/data/feed/api/user/. There is a really simple soloution for this, if we return to the oauth example from the guide:
[py]gd_client = gdata.photos.service.PhotosService()
gd_client.auth_token = authsub_token
gd_client.UpgradeToSessionToken()[/py]
This is a cut out where you get the “use once” token back and upgrade it to a session token. Here you can do two things to make the gd_client work with the oauth user as a default all the time, either:
[py]gd_client = gdata.photos.service.PhotoService(email=’default’)[/py]
or
[py]gd_client.email = ‘default'[/py]
Then it all will work just fine!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: