ProWorks Blog Rotating Header Image

Flickr API Search Package for Umbraco

FlickrA recent ProWorks project had a need to pull Flickr photos from their community to display on their web site. I had never played with the Flickr API so I thought: “cool!”. I couldn’t find a Flickr Umbraco plugin on our.umbraco.org so I dug in and did it myself.

Thank goodness I found the Flickr.Net API Library. That nice little library took a daunting (or at least time consuming) task and made it fun. Also, the Flickr API Explorer for the flickr.photos.search method was very nice for testing.

On to the package…

Download ProWorks Flickr API XSLT Search 2.0 (58 KB) - Tested in Umbraco 4.0.x and 4.5

The package mainly consists of an XSLT extension called ProWorks.FlickrXSLTSearch. This extension has six methods of searching for and returning photos from Flickr: ByUser, ByGroup, ByFreeText, BySet, ByTag and ByUserAndTag.  In addition there are versions of each that support paging using Flickr API calls.

In addition, there is a sample XSLT and two data types to help let your users choose the search in a content page. The data types are the “sort mode” and “tag mode” selections options available in the Flickr photo search method.

How To Install:

1. Install the package from the “Packages/Install local package” item in the “Developer” section in the Umbraco Admin area. (Normal package install)

2. Get a Flickr API key for your website

To get a key go to this page: http://www.flickr.com/services/api/keys and sign up. Your should get your key right away.

3. Add the config into your web.config and add your API key.

<configuration>
  <configSections>
    <section name="flickrNet" type="FlickrNet.FlickrConfigurationManager,FlickrNet"
       allowLocation="true" />

    ...
  </configSections>

  <flickrNet apiKey="yourFlickrAPIKeyGoesHere" secret="yourSecretGoesHere"
       cacheDisabled="true" >
  </flickrNet>

...

<configuration>

This could be an external file as well.

If you want to use the FlickrNet caching, then make your config section look something like this:

  <flickrNet apiKey="yourFlickrAPIKeyGoesHere" secret="yourSecretGoesHere"
       cacheLocation="C:\\YOURWEBSITELOCATION\\App_Data" cacheSize="26240000" cacheTimeout="1:00:00" >
  </flickrNet>

4. Add the FlickrPhotoList Macro to a page or template.  It should display a list of Tree photos.

To customize the search see the documentation below.

Feel free to ask questions or comment below. The rest of the post will be the method documentation and the format that the search results are returned.


Methods

Note: all methods have nearly the same parameters so I will only list the new or different params after the first method description.

ByUser()

Summary: Use the Flickr API to search for all photos by a user.

Params:

  • flickrUserId: User Id from Flickr (i.e. 12345678@N12)
  • flickrSizeMSTB:
    • s = small square 75×75
    • t = thumbnail, 100 on longest side
    • m = small, 240 on longest side
    • - = medium, 500 on longest side (default)
    • b = large, 1024 on longest side (only exists for very large original images)
  • flickrThumbSizeMSTB:
    • s = small square 75×75
    • t = thumbnail, 100 on longest side
  • numberOfPhotos: Integer. The maximum allowed value is 500.
  • flickrSortOrder: The possible values are: date-posted-asc, date-posted-desc, date-taken-asc, date-taken-desc, interestingness-desc (default), interestingness-asc, and relevance
  • minTakenDate: Minimum taken date. Photos with an taken date greater than or equal to this value will be returned.
  • maxTakenDate: Maximum taken date. Photos with an taken date less than or equal to this value will be returned.

Returns: XML resultset (XPathNodeIterator)

XPathNodeIterator ByUser(string flickrUserId, string flickrSizeMSTB, string flickrThumbSizeMSTB, int numberOfPhotos, string flickrSortOrder, string minTakenDate, string maxTakenDate)

ByGroup()

Summary: Use the Flickr API to search for all photos by a group id.

Params:

  • flickrGroupId: Group Id from Flickr (i.e. 12345678@N12)
  • NOTE: Same params as ByUser with the exception of “flickrUserId”

XPathNodeIterator ByGroup(string flickrGroupId, string flickrSizeMSTB, string flickrThumbSizeMSTB, int numberOfPhotos, string flickrSortOrder, string minTakenDate, string maxTakenDate)

ByFreeText()

Summary: Use the Flickr API to search for all photos for a full text search of title, tags, and description.

Params:

  • searchText: A free text search. Photos who’s title, description or tags contain the text will be returned. You can exclude results that match a term by prepending it with a – character.
  • NOTE: Same params as ByUser with the exception of “flickrUserId”

XPathNodeIterator ByFreeText(string searchText, string flickrSizeMSTB, string flickrThumbSizeMSTB, int numberOfPhotos, string flickrSortOrder, string minTakenDate, string maxTakenDate)

ByTag()

Summary: Use the Flickr API to search for all photos by one or more comma separated tags.

Params:

  • tagsCommaSeparated: A comma-delimited list of tags. Photos with one or more of the tags listed will be returned. You can exclude results that match a term by prepending it with a – character.
  • tagMode: Either ‘any’ for an OR combination of tags, or ‘all’ for an AND combination. Defaults to ‘any’ if not specified.
  • NOTE: Same params as ByUser with the exception of “flickrUserId”

XPathNodeIterator ByTag(string tagsCommaSeparated, string tagMode, string flickrSizeMSTB, string flickrThumbSizeMSTB, int numberOfPhotos, string flickrSortOrder, string minTakenDate, string maxTakenDate)

ByUserAndTag()

Summary: Use the Flickr API to search for all photos by one or more comma separated tags for a user.

Params:

  • flickrUserId: User Id from Flickr (i.e. 12345678@N12)
  • tagsCommaSeparated: A comma-delimited list of tags. Photos with one or more of the tags listed will be returned. You can exclude results that match a term by prepending it with a – character.
  • tagMode: Either ‘any’ for an OR combination of tags, or ‘all’ for an AND combination. Defaults to ‘any’ if not specified.
  • NOTE: Same params as ByTag with the exception of “flickrUserId”

XPathNodeIterator ByUserAndTag(string flickrUserId, string tagsCommaSeparated, string tagMode, string flickrSizeMSTB, string flickrThumbSizeMSTB, int numberOfPhotos, string flickrSortOrder, string minTakenDate, string maxTakenDate)

BySet()

Summary: Use the Flickr API to search for all photos in a set.

Params:

  • photoSetId: The id of the photoset to return the photos for.
  • numberOfPhotosPerPage: Integer. Number of photos per page. The maximum allowed value is 500.
  • page: Integer. The page of results to return.
  • NOTE: The flickrSizeMSTB and flickrThumbSizeMSTB work the same as the other methods.

XPathNodeIterator BySet(string photoSetId, int numberOfPhotosPerPage, int page, string flickrSizeMSTB, string flickrThumbSizeMSTB)

Additional Methods “WithPaging”

Summary: Allows for paging on Flickrs end.  Adds a new parameter “page” and replaces “numberOfPhotos” with “photosPerPage”.

Params:

  • page: Integer. The page of results to return.
  • photosPerPage: Integer. Number of photos per page. The maximum allowed value is 500.
  • NOTE: Same params as related method

Result XML

Fields:

<photolist> contains many <photo>s

<photo> object attributes:

  • title: Image title as set by the image owner
  • imagefile: File location URL on Flickr in the size specified by the “flickrSizeMSTB” param
  • thumbnail: File location URL on Flickr in the size specified by the “flickrThumbSizeMSTB” param
  • flickrpageurl: URL to the Flickr page for this photo
  • ownername: Flickr user that has the photo on their account
  • latitude: Latitude this photo was taken at
  • longitude: Longitude this photo was taken at
  • datetaken: Date photo was taken
  • tags: tags assigned to this photo
  • views: views on Flickr of this image

Sample:

<photolist>
<photo title="Call of the Raven (formerly Nature's Special Effects)" imagefile="http://farm1.static.flickr.com/33/63452603_b3a5b5448d.jpg" thumbnail="http://farm1.static.flickr.com/33/63452603_b3a5b5448d_t.jpg" flickrpageurl="http://www.flickr.com/photos/72164905@N00/63452603" ownername="Walkabout Wolf" latitude="47.149625" longitude="-121.566724" datetaken="2005/11/14" tags="" views="-1"></photo>
<photo title="Fascinating Nature - First Double Rainbow 2010" imagefile="http://farm3.static.flickr.com/2710/4466953793_cd0430ba59.jpg" thumbnail="http://farm3.static.flickr.com/2710/4466953793_cd0430ba59_t.jpg" flickrpageurl="http://www.flickr.com/photos/21207178@N07/4466953793" ownername="Batikart" latitude="48.798242" longitude="9.280571" datetaken="2010/03/27" tags="" views="-1"></photo>
<photo title="The Earth, The Sky And A Tree" imagefile="http://farm5.static.flickr.com/4016/4457682328_5425b08a1e.jpg" thumbnail="http://farm5.static.flickr.com/4016/4457682328_5425b08a1e_t.jpg" flickrpageurl="http://www.flickr.com/photos/8407953@N03/4457682328" ownername=".: Philipp Klinger :." latitude="50.377929" longitude="8.774814" datetaken="2010/03/22" tags="" views="-1"></photo>
<photo title="Touchdown, Part II" imagefile="http://farm5.static.flickr.com/4061/4398070785_453712aaef.jpg" thumbnail="http://farm5.static.flickr.com/4061/4398070785_453712aaef_t.jpg" flickrpageurl="http://www.flickr.com/photos/8407953@N03/4398070785" ownername=".: Philipp Klinger :." latitude="50.378586" longitude="8.767776" datetaken="2009/06/07" tags="" views="-1"></photo>
</photolist>

36 Comments

  1. Greg says:

    Awesome – thanks for sharing. I’m currently rebuilding my own website, and was going to build this exact thing when i got to it… I will probably extend yours a little if the source code is available?

  2. Jason says:

    Hey Greg,

    Yea, I’ll get this up on CodePlex so others can contribute. I’ll work on that over the next couple of weeks as I haven’t done that before! :)

    Love to hear any feedback until then.

  3. Cool! I’ve been thinking of doing the same thing but never got around to it… Thanks Jason! Look forward to trying it out!

  4. okay, what am i doing wrong? i get nothin’

  5. Jason says:

    Bob: Which call are you trying? ByTag()?

  6. i was trying… ByTag() and ByUser() both displayed nothing… i merely updated the xslt with the correct call and params, did i miss something??

  7. Jason says:

    I’ll try installing it on a clean install and see what happens.

  8. Jason says:

    Oops, its the API key that is invalid. Let me take a look and fix it up.

  9. Jason says:

    Key info:

    Get an API Key

    To get started you will need to get an API Key for use with Flickr. You apply for new keys and manage your keys from the Your Keys section of the Flickr Services Web site at http://www.flickr.com/services/api/keys. Applying for a new key should be a pretty instantaneous affair. Once you get your API Key, you can return to the same page and click the Edit Configuration link. This will allow you to edit the description of the use of your API Key and show you your Shared Secret, which you will need if you want to perform authenticated requests to Flickr.

  10. Jason says:

    I think if you get a key from Flickr for your domain it will work because its not doing any authentication.

    However, I’m going to add a config file to the project to explicitly set the key. And I want to make a couple of changes to the initial page/macro to make things more obvious.

    Thanks for giving it a try and letting me know it doesn’t work right out of the box!

  11. Jason says:

    Bob,

    I posted something in the our.umbraco.org forum to help you get your current version up and running until I create a new package.

    http://our.umbraco.org/projects/flickr-api-search—xslt-extension/bug-reports–questions/9338-Not-working-on-initial-install

    Let me know if you still have issues.

  12. Jason – that did the trick! thanks for helping me out! i cannot wait to integrate this with fancyBox :)

  13. hey, is there the ability to search by set? basically, i would want a user to upload a set of photos to flickr… then paste the photoset ID to make a gallery page in their umbraco….

    any thoughts?

  14. Jason says:

    Good idea! There is a way to do that. I’ll have to add that in to the next release. Shouldn’t be too hard, but I may not get to it for a week or so.

  15. no worries… thanks for all that you do! hey, you going to codegarden?

  16. Jason says:

    Unfortunately, no. I made an effort, but the airline miles apparently need to be redeemed more that 4 mos in advance to go to Europe… I REALLY wanted to go too…

    Are you going?

  17. yeah, i was able to figure some stuff out and get there…

  18. Jason says:

    Bob,

    I finally got some time and added the BySet() and ByUserAndTag() methods to the package.

    I’m going to test it with 4.5 and then release it shortly (week or so)

    Anything else quirky or buggy that I can fix quickly?

    -J

  19. Thom says:

    Hi Jason,

    great news regarding the BySet() method. What I’ve been waiting for.

    Is this extension just going to target 4.5 now or will it still work with 4.0.x releases? We’re not migrating over to 4.5 for existing sites for a while yet…

    Keep up the good work!

  20. Jason says:

    Thom,

    I’m going to test in 4.5 and I hope it will work in both seamlessly. It should I think, but if it doesn’t then I’ll make a 4.0.x version too.

    Thanks!
    Jason

  21. Jason says:

    OK, version 2.0 is up!

    I tested in 4.5 and it worked great. This version should work in both versions.

  22. Johan says:

    there is something oddly. after having installed ProWorks Flickr, the xslt works ok but after I changed it the second time it does not work. so I reinstall the package and then it works again. have done it 3 times now.

    beyond that. thanks for the package is really cool.

    Johan

  23. johan says:

    oh yes. I should probably have written in here too and say it was ok ..

    and thanks for help

  24. David Lerche says:

    Hi.
    I have implemented above, but can’t seem to find a way to display all available sets for e.g. a given user. This could be a nice feature, so that it is possible to just upload new sets, that automatically will be displayed on the website.

    Perhaps it’s just me that don’t know how to do so, as i’m quite new to XSLT and Umbraco.

  25. David Lerche says:

    By the way, can recommend to implement LightBox 2 along with this solution, it’s very easy to do:
    http://www.huddletogether.com/projects/lightbox2/#example

  26. Jason says:

    Good point David. A way to get all sets is a great idea.

    I’ll try to get that into the next version.

  27. Jason says:

    David,

    I love how easy it is to create cool photo areas on websites with this plug-in.

    Here’s a place we used it: http://www.davincidays.org/

    The tooltips were easy to add too!

    If you have an example of taking this library/plug-in and lightboxing it, I’d love to link to it!

  28. Rik says:

    I just tried installing this package for 4.6.1 and came to the conclusion that there’s something wrong, the macro has no properties as shown in the screenshots on our.umbraco.org, and in the end it doesn’t return any photo’s…

    this might need some additional testing.

  29. Jason says:

    Thanks for the heads up Rik. I’ll test it in 4.6.1 and see if I have any issues.

    Quick question: did you read the “How To Install:” section in the blog above and complete all the steps?

    Thanks,
    Jason

  30. Rico says:

    Thanks for the package Jason, really cool. Got it up and running with the bySet method. One small question: how do you call the “WithPaging” methods?

  31. Jason says:

    Hey Rico,

    They are additional methods on the XSLT extension. Make sure you are using the latest version above and they should appear in the extension methods.

    Thanks,
    Jason

  32. Tom says:

    Hi Jason, really liking this package!
    It is very useful and works beautifully, but I have a question.. How would I go about adding parameters so that I can specify the userID/number of photos etc when inserting the macro into a page?

    Any help would be greatly appreciated!

    Thanks

  33. Jason says:

    Tom,

    Did you know that I had released the Flickr package as an open source project?

    http://umbracoflickrapi.codeplex.com/

    Thanks,
    Jason

  34. Greg says:

    Having trouble getting the source version of the project working. I’ve compiled it and added the reference to my web site, but I am getting an error. Here’s a snippet:

    System.Xml.Xsl.XslTransformException: Cannot find a script or an extension object associated with namespace ‘urn:ProWorks.FlickrXSLTSearch’.

    What references do I need to be using for the namespace.

  35. Jason says:

    Greg,

    Have you added the XSLT Extension to the xsltExtensions.config?

    It may be best to install the package first, then update the DLLs with the version you compile from the local source.

    Thanks,
    Jason

Leave a Reply