Before you ask... Yes, I struggled with the title of this post, but give me a break, it's 4:30 am here! " src="http://www.hackviking.com/wp-includes/images/smilies/icon_smile.gif" />
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:
gd_client.InsertAlbum(title='Test', summary='a test album')
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:
<title type='text'>Trip To Italy</title>
<summary type='text'>This was the recent trip I took to Italy.</summary>
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:
gd_client = gdata.photos.service.PhotosService()
gd_client.auth_token = authsub_token
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:
gd_client = gdata.photos.service.PhotoService(email='default')
gd_client.email = 'default'
Then it will all work just fine!