// simple flickr image search demo - November 2011 - rtwomey@u.washington.edu // // flickr API details here: // http://www.flickr.com/services/api/ // // register for a developers key here: // http://www.flickr.com/services/apps/create/apply/ PImage[] images; // array to hold images int imageIndex; // which image are we currently showing void setup() { size(800, 800); background(0); String baseURL = "http://api.flickr.com/services/rest/?"; // address for flickr web services String apiMethod = "flickr.photos.search"; // search flickr photos String apiKey = "bd7435660785b923332b224789d33c93"; // this key was floating around processing.org, bad form String searchString="tjhsst"; // search string String query = baseURL+"method="+apiMethod+"&text="+searchString+"&api_key="+apiKey+"&per_page=40"; // do actual query call XMLElement xml = new XMLElement(this, query); // holds the results //println(xml); // gather results XMLElement[] photoTag = xml.getChildren("photos/photo"); // get just the photos println(photoTag.length + " images"); images = new PImage[photoTag.length]; //loop over images for (int i = 0; i < photoTag.length; i++) { String farm = photoTag[i].getString("farm"); String server = photoTag[i].getString("server"); String id = photoTag[i].getString("id"); String secret = photoTag[i].getString("secret"); String img = "http://farm"+farm+".static.flickr.com/"+server+"/"+id+"_"+secret+".jpg"; images[i] = requestImage(img); // alternately, save me for later. see flickr_api_array.pde } if(images.length<=0) { println("sorry, no results"); exit(); } } void draw() { background(0); if (images[imageIndex] != null) { image(images[imageIndex], 0, 0); } fill(0); ellipse(15, 15, 20, 20); fill(255); text(imageIndex, 16, 14); if (frameCount % 60 == 0) { imageIndex++; if (imageIndex >= images.length) { imageIndex = 0; } } }