Archive for the 'API' Category

Digg Releases API

Digg.com has just realeased an API (Application Programming Interface) for web sites or application developers who would like to use their data. I can already think of some good uses for their data. Things like displaying any stories from your site that have been dugg can now be done through the API.

I’m on Twitter

I signed up for a Twitter account. If you don’t know what Twitter is, it is the latest, greatest, social/Web 2.0 web application. The idea is to post what you are doing. You can add friends so you can see what your friends are doing. My username is bikeride. You can send or get updates from a mobile device or IM. I’d like to use the API to automatically update Twitter when I publish a blog post, create a new flickr photoset, bookmark something with del.icio.us, or share an item in google reader, or add a new training log entry. Maybe I’ll get to it.

Geocode your photos with Flickr

Flickr just added the ability to geocode your photos. I’m sure I will be wasting a lot of time playing with this. I already stayed up late last night mapping my photos with the nifty Flickr photo organizer. The Flickr API has been updated so that now you can access the geocoding data. I can already think of some cool ways to use this. For example, it would be cool to show photos tagged with cycling near the loctaion of the events listed in bikeride.com. To learn more how to geocode your photos, go to the Flickr blog post.

Flickr API Example using ASP and JScript

I recently set up the photo gallery page of BikeRide.com using the Flickr API. I wanted to pull in all my sets that include cycling photos. I couldn’t see an API method for making a call to get all my sets with photos containing the tag “cycling.� That would have been the best way to make a maintenance free page, but I have to start with making an array containing the setIds of my cycling related photos.

The code loops through the ids, make an API call to get the set information including the title, description, number of photos in the set, and the id of the primary photo to display for the set.

The next step is to make an API call to get individual photo information to get the URL for the image on Flickr. The code example is below.


output='';
galleryHTML='';

// Lock application and set variable for caching purposes
Application.Lock();	//Lock the application object

if (new Date().getTime() > (Application("galleryTime") + 36000)) { // caching - execute if more than 10 minutes old;

	// My Flickr Set IDs - Just add a new id the next time a set is added to flickr
	setIds = new Array(
		'72157594215842408', //2006 FSA GRAND PRIX
		'72157594214549645', //2006 RAMROD
		'72157594201502432', //2006 NYC Triathlon
		'72157594168641657', //2006 Pat Griskus Triathlon
		'72157594146912138', //2006 EBCC Bash Bish 200K
		'72057594121299286', //2006 Shelbourne Falls 200K
		'72057594079933400', //2006 Plainville Crit
		'1352705', //2005 Chainbiter Cross
		'1145739', //2005 Litchfield Fall Ride with Gordon
		'712816', //2005 Tour of the Litchfield Hills
		'415217', //2005 Quabin 200K
		'408170', //2005 Tour of CT
		'408191', //2005 Bershire 300K
		'408452', //2005 Berkshire 100K
		'762107', //2004 Chainbiter Cyclocross
		'411413', //2004 Southington Cyclocross
		'411569', //2004 Stockbridge Century
		'408851', //2004 Philly USPRO
		'767925', //2004 Tour of CT
		'762481' //2003 World Championships
	)

	for (i=0;i<setIds.length;i++) {
		url = 'http://www.flickr.com/services/rest/?method=flickr.photosets.getInfo&photoset_id='+setIds[i]+'&api_key=[myFlickrKey]'

		// Create an ASP XML parser object
		var xml = Server.CreateObject("MSXML2.ServerXMLHTTP.4.0")
		xml.open("GET", url, false);
		try {
			xml.send();
			if (xml.status == 200) {

				xmlDoc = xml.responseXML
				xmlDoc.setProperty("SelectionLanguage", "XPath");
				photoset = xmlDoc.selectNodes("//photoset")
				if (photoset && photoset.length > 0) {
					setId =  photoset[0].getAttribute("id");
					photoId = photoset[0].getAttribute("primary");
					server = photoset[0].getAttribute("server");
					count = photoset[0].getAttribute("photos");
					title = photoset[0].getElementsByTagName("title")[0].firstChild.nodeValue;
					desc = photoset[0].getElementsByTagName("description")[0].firstChild.nodeValue;
					imgurl = photoId;

					//Now make anothe API call to get the right photo size to dislplay
					var xmlSizes = Server.CreateObject("MSXML2.ServerXMLHTTP.4.0")
					sizesURL = 'http://www.flickr.com/services/rest/?method=flickr.photos.getSizes&photo_id='+photoId+'&api_key=[myFlickrKey]';
					xmlSizes.open("GET", sizesURL, false);
					try {
						xmlSizes.send();
						if (xmlSizes.status == 200) {
							xmlSizesDoc = xmlSizes.responseXML;
							xmlSizesDoc.setProperty("SelectionLanguage", "XPath");
							sources = xmlSizesDoc.selectNodes("//size[@label='Square']");
							if (sources && sources.length > 0) {
								imgurl = sources[0].getAttribute("source");
							}
						}
					} catch(e) {

					}
					xmlSizes = null;
					// Build the html to output - ok - I know I need to take my css
					output += '<div class="photobox"'>'
					output += ''<div class="galleryphoto"><a href="http://www.flickr.com/photos/bikeride/sets/' + setId + '/">'<img src="'+imgurl+'" width="75" height="75" border="0" alt="'+title+'" />'</a></div>'
					output += ''<div style="height: 85px;">'
					output += ''<strong>'+title+'</strong> ('+count+' photos)<br />\n'
					output += desc + ' ';
					output += ''<a href="http://www.flickr.com/photos/bikeride/sets/'+setId+'/">View Photos ...</a>\n'
					output += ''</div>'</div>\n'

				}

			}
		} catch(e) {

		}
		xml = null;
	}

	if(output != '') {
		Application("galleryHTML") = output;
	}

	Application("galleryTime") = new Date().getTime();

}		

galleryHTML = Application("galleryHTML");

Application.UnLock();	//Unlock the application object

Response.Write(galleryHTML);

I will still need to add an Id to the code the next time I add a set of cycling photos, but that is it. I would like to play more with the API and make an Ajax style photo gallery on top of the Flickr API.




About Brent

I have been a Web Developer since the early '90s working on some of the highest traffic sites on the internet such as MSN.com and ESPN.com. Since 2007 I have been using Ruby on Rails while working for Sports Technologies, a small internet company in Connecticut, developing features for FanNation.com and Fantasy Sports applications for Sports Illustrated.

I am interested in all things related to Social Media, User Experience, and creating great Web Applications.

I am a Cycling enthusiast who raced competitively for many years, and still try to get out and ride as much as I can. I created the site BikeRide.com and have developed some other cycling related sites in the past.

I am a husband, and the father of two girls. I grew up in western Washington, but now live in Connecticut.