Sunday, February 20, 2011

Fetching and displaying images from flickr

I was starting on a website which should retrieve images from Flickr. This needed some investigation so I want to share it with you.

First thing you'll have to do is to request an API key. Nowadays you can login with your Google or Facebook account which is really cool of yahoo. Add this key to your appSettings
and add the following code to retrieve a list of urls:
WebRequest tokenRequest = WebRequest.Create(string.Format(
tokenRequest.Method = "GET";

WebResponse tokenResponse = tokenRequest.GetResponse();
var photos = new List<string>();
var xml = new XmlDocument();
xml.Load(new StreamReader(tokenResponse.GetResponseStream()));
foreach (XmlNode node in xml.ChildNodes[1].ChildNodes[0].ChildNodes)
I used the to search all images of a specified user. You can check the misc urls of the Flickr API to see how the url can be build. Off cource the code above can be changed to make use off Xml Serialization, but for now reading the attributes of the photo's is enough for me.

No comments:

Post a Comment