Showing posts with label flickr. Show all posts
Showing posts with label flickr. Show all posts

Tuesday, 19 October 2010

Accessing Picasa's atom feed API from Spring's REST and XPath templates

Been swearing at my screen and Google's choice of atom based API for their Picasa web albums. Flickr's REST API took 10 seconds to work out. Picasa: days...


My problem:

Trying to parse album ids from Picasa's API: code.google.com/apis/picasaweb/docs/2.0/developers_guide_protocol.html#ListAlbum.


Source picasaResponse = restTemplate.getForObject( albumsURL, Source.class, parameters );

Jaxp13XPathTemplate xpathTemplate = new Jaxp13XPathTemplate();

Collection albumIds = xpathTemplate.evaluate("//entry",

      picasaResponse, new NodeMapper(){

   public Object mapNode(Node node, int i) throws DOMException {

      Element album = (Element) node;

      log.debug("IN NODE ALBUM");

      return null;

   }

}


This never worked. It should have I thought. Trying different combinations of "/entry", "/feed/entry", "//atom:entry", "/atom:feed/atom:entry", swapping with Jaxen, etc made no impact.


Then after some googlebashing and soulsearching I solved the problem.

The Xpath template needs a namespace to resolve the atom xml. So adding this solved the problem:


Source picasaResponse = restTemplate.getForObject( albumsURL, Source.class, parameters );

Jaxp13XPathTemplate xpathTemplate = new Jaxp13XPathTemplate();

Properties namespaces = new Properties();

namespaces.setProperty("atom",

   "http://www.w3.org/2005/Atom");

xpathTemplate.setNamespaces(namespaces);

Collection albumIds = xpathTemplate.evaluate("//atom:entry",

      picasaResponse, new NodeMapper(){

   public Object mapNode(Node node, int i) throws DOMException {

      Element album = (Element) node;

      log.debug("IN NODE ALBUM");

      return null;

   }

}




Ps. code simplified and not using bean injection etc for clarity.

Friday, 27 February 2009

My band's next album


someone else is driving
Originally uploaded by flurdy




This could be my band's next album.

Except I don't sing nor can I play an instrument, therefore I do not play in a band...


But the "My band's next album" gimmick is cool. I got it from Henrik Tandberg on Facebook.

For this I used a photo by daliborlev: www.flickr.com/photos/mr_gonzales and a quote by David Letterman.


For your own album follow these guidelines:

---

1 - Go to "wikipedia." Hit “random”
or click en.wikipedia.org/wiki/Special:Random
The first random wikipedia article you get is the name of your band.

2 - Go to "Random quotations"
or click www.quotationspage.com/random.php3
The last four or five words of the very last quote of the page is the title of your first album.

3 - Go to flickr and click on “explore the last seven days”
or click www.flickr.com/explore/interesting/7days
Third picture, no matter what it is, will be your album cover.

4 - Use photoshop or similar to put it all together.

5 - Post it to Facebook with this text in the "caption" and TAG the friends you want to join in. (you can untag yourself if you don't want this photo up)


---

My, flurdy, changes to these rules are:

---

3 - Follow the 3rd step, but make sure the photo has a license which allow reproduction. I would suggest looking at flickr.com/creativecommons.

4 - Instead of photoshop, I se picnik.com. Its free and online, and with the firefox extension links directly from flickr.

5 - I posted mine back to flickr and now to my blog.

---

The picture by daliborlev was licensed under CC-by-sa-nc, while my normal flickr work is CC-by-sa, so I had to add nc to this album photo.