Click here to Skip to main content
15,911,896 members
Articles / All Topics
Technical Blog

Google Picasa API Python: Developers Guide

Rate me:
Please Sign up or sign in to vote.
4.80/5 (2 votes)
30 Oct 2013CPOL2 min read 6.5K   2  
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 am using the Picasa API. I found this great guide from Google with examples here. It's far from complete but the examples push 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 into 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 had 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 requests 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:

C#
gd_client.InsertAlbum(title='Test', summary='a test album')

Where the gd_client is an instance of gdata.photos.service.PhotosService() with the oauth token already 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:

POST https://picasaweb.google.com/data/feed/api/user/userID

XML
<entry xmlns='http://www.w3.org/2005/Atom'
xmlns:media='http://search.yahoo.com/mrss/'
xmlns:gphoto='http://schemas.google.com/photos/2007'>
<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'
term='http://schemas.google.com/photos/2007#album'></category>
</entry>

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 solution for this, if we return to the oauth example from the guide:

C#
gd_client = gdata.photos.service.PhotosService()
gd_client.auth_token = authsub_token
gd_client.UpgradeToSessionToken()

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:

C#
gd_client = gdata.photos.service.PhotoService(email='default')

or:

C#
gd_client.email = 'default'

Then it will all work just fine!

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Sweden Sweden
I develop in C# on .Net platforms like MVC. Like to use jQuery to build rich interfaces. I also blog about development and snags I got and the solutions I found for them.

I also a full time CIO at a Swedish energy company. When there is time I do some part time consulting on cloud issues.

Comments and Discussions

 
-- There are no messages in this forum --