Today I tried to share a list of photos from my best friend’s wedding with various internet services. Since Facebook for Android is not capable of uploading multiple images at once I decided to upload them to Google Picasa Web albums first. Afterwards I switched their visibility to a restricted circle of users and shared them with Google+. Unfortunately not many wedding guests use G+ but mostly favor Facebook. Lazy as I am I didn’t want to transfer the photos from my mobile to the desktop and upload them again (using the MTP protocol propagated by ICS/JB//Nexus doesn’t work well on Linux anyway) so I looked for a way to download all of the Picasa Web Album shots using the Picasa API.
Here you’ll get an overview of available endpoints: https://developers.google.com/picasa-web/docs/2.0/developers_guide
Note that the Picasa Wen Albums Data API strongly deals with XML, media and ATOM formats so it should be rather easy to parse the results. I decided to go with the album list first:
You can use the long integer that is shown on your Google/+ profile’s URL as <yourUserId>. That one yields a document containing all albums. Note that you have to get a valid OAuth access token if you’d want to get the contents from within your own software – for this simple usecase it’s sufficient to use a browser window that holds your Google authentication cookies. To save the results you can simply save a page locally.
That document will yield an ATOM document containing the authenicated user’s albums. Find the album that you want to retrieve pictures from and copy the href-link from the <link rel=’http://schemas.google.com/g/2005#feed’ … > element. Note that by default settings that document won’t contain links to the full size images. To let the API yield those, add another parameter to the URL, right after the auth-key: &imgmax=d . The url should look like that:
Open that one in your browser window again and save its contents. Note that the API restricts you to 30 images by default. If you need more add yet another parameter: &max-results=1000. Now you can parse the XML result using your favorite tools. Since I’m on Linux I chose xmlstarlet that can be easily installed using apt:
sudo apt-get install xmlstarlet
This little XML-suite contains tools to execute XPath expressions on documents from the command line. Additionally you could also apply XSLT transformations. To get the plain image media sources from the last document retrieved you’ll issue this command:
xmlstarlet sel -t -v "//media:content/@url" your_document.xml > origs.txt
origs.txt will now contain a line-broken list of original images. To finally retrieve them you can use wget (that should come with your standard installation; if not: sudo apt-get install wget):
wget -i origs.txt
and voila: there are all your images 🙂
- http://www.jedi.be/blog/2009/04/30/download-all-original-pictures-from-flickr-and-picasa-via-rss-in-iphoto/ The initial article
- https://developers.google.com/picasa-web/docs/2.0/reference#Parameters All parameters that apply to the Google Picasa Web Album API
- http://www.w3schools.com/xpath/default.asp XPath expressions
- http://xmlstar.sourceforge.net/ XMLStarlet home