Using API Flickr with jQuery

I built an script for my personal website, it chooses a random picture from my uploaded gallery on flickr.

I hope the comments on the code are enough for you to understand

		var flickr_APIkey = '3b68835445aa2001d41724b2f58943cd';      // get yours at: http://www.flickr.com/services/api/
		var flickr_UserId = '8847785%40N07'                          // GerManson
	
		// defining REST API URLs
		var flickr_getContactPhotos = "http://api.flickr.com/services/rest/?method=flickr.photos.search&api_key="+ flickr_APIkey +"&user_id="+ flickr_UserId +"&lang=en-us&format=json&jsoncallback=?";
		var flickr_getPhotoInfo = "http://api.flickr.com/services/rest/?method=flickr.photos.getInfo&api_key="+ flickr_APIkey +"&lang=en-us&format=json&jsoncallback=?&photo_id=";
		
		// getting a jquery object for the body of the page, be sure to add and id to your body tag 
		var body = $("#body");
	
		$.getJSON(flickr_getContactPhotos, function(data) {
	
			// selecting a random item from the images array
			var rnd = Math.floor(Math.random() * data.photos.photo.length);
			var image = data.photos.photo[rnd];
			
			flickr_getPhotoInfo += image.id;
			
			$.getJSON(flickr_getPhotoInfo, function(info) {
				image.osecret = info.photo.originalsecret;
				image.ext = info.photo.originalformat;
				
				// building the image_url http://www.flickr.com/services/api/misc.urls.html
				var image_url = "http://farm" + image.farm + ".static.flickr.com/" + image.server + "/" + image.id + "_" + image.osecret + "_o." + image.ext; 
			
				body.css("background-image", "url("+image_url+")");
			});
			
		});

User Comments

to leave a comment.
No comments had been made.