Flickr.Net API Library – 2.0.1

Just some bug fixes, plus adding a few more supported methods and parameters to the code. I also finished the code comments, so intellisense should now show up something for each method at least.

[Download and Release Notes](http://www.wackylabs.net/flickr/flickr-api)

[tags]flickr, flickrapi, flickrdotnet, .net[/tags]

Robert Burke – Flickr Assistance

Just a quick post to introduce another application which is using the Flickr.Net API Library.

Rob Burke has been helping me for a while with various problems we where having with the code, most specifically the Medium Trust stuff, so a big thanks to him. He’s also developed what could be a very useful little tool for helping to sync a local copy of images against Flickr. I’ve yet to give it a try, but there is certainly a need for this kind of tool.

Robert Burke’s Weblog : Introducing Little Syncr

Flickr.Net API and Medium Trust

I’ve had a few requests to get the FlickrNet API Library working in Medium Trust mode under ASP.Net, so I thought I’d look at it. Here lies the tales and tribulations that such a journey took.

What is ‘Medium Trust’?

Good darn question. I wasn’t actually sure until I looked it up. Basically its a more secure environment for ASP.Net, often in which you might find yourself if using ASP.Net hosting on a shared server. It means you can’t iterate through all the directories on the server and read a load of files, and it also has other restrictions, which I’ll get to in a bit. (Read this for more details on the permission levels for each type of built in trust level.)

Where To Start

First thing is first, put a test web site into ‘Medium Trust’ mode.

Add the line to your system.web of either your applications web.config (for testing) or your machine.config.

<trust level=”Medium” />

Easy so far.

The only thing is this just gave me a generic “SystemException: Security error” which was no help whatsoever.

What Next?

Turns out that if I took OUT the [assembly:AssemblyKeyFile()] attribute from the AssemblyInfo.cs file it got rid of the above error, and gave me another one. But at least this new one has a line number associated with it! I still haven’t managed to find a reason for this, but for now the FlickrNet assembly isn’t signed. I shall probably have to start distributing a signed and a none signed version if I can’t find an answer to this one.

(Update: Found out what the problem was here. When in Medium Trust mode the web application is considered a ‘partial trust’ application and by default code libraries do not allow partial trust applications to call them. I’ve added the AllowPartialTrustCallersAttribute() to the assembly and this is now working correctly. Hurray. See here for blog post)

File IO Errors

The main effect that Medium Trust has is on file access. You are not allowed to browse directory or create files outside of your own virtual web directory. Therefore I was obviously going to have to look in further detail at the caching infrastructure, specifically where it created these files.

I made all these changes (eventually), as well as adding the ability to specify the cache location from within the configuration file (and then added the ability to specify it at runtime as well, which took a bit more work).

Unmanaged Code

I didn’t have any unmanaged code in the API, or so I thought. Then I came across a bit of code which called the Marshal.GetHRForException method. This converts a .Net Exception into a HRESULT integer, i.e. an old school Win32 error code. The code in question was used to distinguish a file locked error from other types of IOExceptions. And hopefully unsuprisingly (from the description I’ve just given you) you should be able to tell that this method is effectively a call out to unmanaged code. I’ve yet to work out a replacement for this code so at the moment its commented out.

Miscellaneous others

Other various things I had to work around was access to System.Net.WebProxy.GetDefaultProxy() static method, which throws an exception if called in Medium Trust. So I wrapped a try catch around this to catch that error. Then it turned out you cannot assign “null” to a HttpWebRequest.Proxy property if you are running in Medium Trust as well. Strange I though, but thats fine too (who wants to assign null to it anytime!)

The Final Stumbling Block – Shot in the Head?

Finally, everything compiled and I could create an actual Flickr class instance successfully. Then came the time to perform a quick test to Flickr.

Bam – turns out that any WebRequest to any web site (apart from the local web server) is blocked under Medium Trust. What? How is anyone ever going to use the FlickrNet API library under these scenarioes.

There is a Code Access Security document that is included with DotnetNuke that says the following code in your web.config will fix this particular problems:

<trust level=” ” originUrl=”http://www.flickr.com/*” />

The document also details ways to create a custom medium trust level. So if you are working in a modified medium trust envorinment you probably wont have this problem. You’ll either have to ask your hosting provider or just play around to see what works.

As an aside, if working in the above Medium environment then picture downloading will not work, as pictures are hosted at http://static.flickr.com and not http://www.flickr.com. But then it you’re working on a web app you probably just want to output the URL to the web page for the user’s browser to download anyway.

Conclusion

It has been a fun run around the .Net Framework for this one little feature, so I hope you all appreciate the work :)

[tags]microsoft, security, asp.net, .net, web, flickrapi[/tags]

FlickrNation Podcast

I’d just like to thank [Thomas Hawk](http://www.thomashawk.com/) who has recently started a new podcast called [FlickrNation](http://www.flickrnation.com). Its up to its 3rd episode so far and I just got some serious pimpage. I must say I really get a huge ego boost out of this kinda thing (I must be slightly shallow I guess :) ).

He mentions my new [Delete Me Resurrection](http://undeleteme.blogspot.com) blog, plus the wonderful (but sometimes hard going) [Entrance To Hell](http://www.flickr.com/groups/entrancetohell/) group.

He’s also got other stuff about things that are happening in the Flickr community, such as the debate that seems to be going on about none photos uploaded to Flickr and their place in the community. Personally I think the lines drawn between ‘art’ and ‘photography’ can be so grey an area I don’t see how you can enforce the distinction.

I also spotted a great Wikipedia article that was article of the day yesterday, about the [Canon T90](http://en.wikipedia.org/wiki/Canon_T90), the last manual focus that Canon produced before they moved on to the EOS range (disclaimer: I have 3 Canon cameras, an Powershot A70 P&S, the EOS 350D digital SLR, and my newest toy, a EOS 300V film camera for messing about old stylee with).

Sea of Chairs

Sea of Chairs


Sea of Chairs, originally uploaded by aqui-ali.

I’ve started up a new blog, which I call Delete Me Resurrection. I’m going to be using it to highlight some of the photos which have failed to be ‘saved’ by the various voting groups on Flickr which I actually like.

So why you ask have I selected the above photo of some green chairs to show you here. Well, firstly it was deleted out of the original Delete Me group. But thats not why I’m showing it you, no.

I decided I didn’t like it enough to resurrect it.

Thats still not why I’m showing it you.

Its because it used to appear on the ‘interesting’ page along side my own ‘most intersting’ photo for March 4th 2005. Infact there used to be two photos on the same theme above my own photo.

And I came across it while I was researching for the blog using the ‘interestingness’ of the ‘deleteme10’ tag.

I thought that was interesting :)

How well do you know your contacts

Following a link from [the FlickrBlog](http://blog.flickr.com/flickrblog/2005/11/how_well_do_you.html) lead me to the most excellent flickr game I have ever played. Basically it shows you a photo from one of your Flickr contacts and presents you with 3 choices – you pick who’s photo you think it is. I seem to be doing quite well at the moment – it seems most of my contacts have quite distinctive styles.

Congratulations once again to FD for some awesome uses of the Flickr API.

[FD’s Name That Contact Game](http://flagrantdisregard.com/flickr/namethatcontact.php)

[Discuss here](http://flickr.com/groups/flickrtoys/discuss/126308/)

Flickr.Net Source Release 1.4.3

The next version of the source code for the Flickr.Net API Library has been released.

[Download Latest Source](/flickr/flickr-api).

See the above page for changelog – there are some good ones in there.

There are also two new ‘examples’ pages.

* [Examples – Part 1](/flickr/flickr-api/examples-part-1)
* [Examples – Part 2](/flickr/flickr-api/examples-part-2)

Feel free to add comments as you want.

Flickr Screensaver 4.0

Finally, its here!

Flickr Screensaver version 4.0

Loads of brand new features

* it now uses the new authentication methods
* image refresh times in 15second intervals (0.25mins)
* new ‘postcard’ optional format (actually just coloured border) with optional rotating of image
* enhanced enlarging of small images to fill the screen (Fill Screen checkbox on options page)
* optional Proxy configuration
* See most recently shown image and link back to Flickr from screensaver config screen

[Download](/flickr/flickr-screensaver “Flickr Screensaver Download Page”)