// google image search demo - November 2011 - rtwomey@u.washington.edu // // google API details: // http://code.google.com/apis/websearch/docs/ // // get a google API key: // get an API key here http://code.google.com/apis/loader/signup.html // // unfortunately, the old RESTful processing API only produces JSON. // this is a pain in the butt. so, you'll need to do some deeper data massaging. // // download the json library and install in processing: // https://github.com/agoransson/JSON-processing // // (or this one // http://www.blprnt.com/processing/json.zip // used in another example project is here (doing something with NYtimes data): // http://blog.blprnt.com/blog/blprnt/processing-json-the-new-york-times import org.json.*; import processing.net.*; void setup() { size(800, 800); background(50); fill(200); String apiKey = "AIzaSyACUZC3H-f2q615RqwcNlfyYPoTFjQ0jMY"; //"YOUR_KEY_HERE"; String baseURL = "http://ajax.googleapis.com/ajax/services/search/images?"; String terms = "Paris%20Hilton"; String query = baseURL+"v=1.0&q="+terms+"&key="+apiKey; String result = join(loadStrings(query), ""); println(result); // create JSON object from string and parse it JSONObject obj; boolean worked=false; try { obj = new JSONObject(result); //println(obj); //println(obj.getNames(obj)); JSONObject responseData=obj.getJSONObject("responseData"); //println(responseData); //println(responseData.getNames(responseData)); JSONArray results=responseData.getJSONArray("results"); //println(results); for (int i=0; i>> "); //println(r); //println(r.getNames(r)); println(r.getString("url")); String imgurl = r.getString("url"); //println(results.get(i)); // display me PImage tmp; tmp = loadImage(imgurl); image(tmp, i*200, i*200); // or store me in an array } } catch(Exception e) { e.printStackTrace(); } } void draw() { // and draw me later }