// google web search demo - November 2011 - rtwomey@u.washington.edu // // 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. // the new method, Google Custom Search, seems to want to only search particular // domains rather than giving you web search. // // google API details: // http://code.google.com/apis/websearch/docs/#fonje // // new search api: // http://code.google.com/apis/customsearch/v1/using_rest.html // // get a google API key: // get an API key here http://code.google.com/apis/loader/signup.html // // download the json library and install in processing: // http://www.blprnt.com/processing/json.zip // // an 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(200, 200); background(50); fill(200); String apiKey = "AIzaSyACUZC3H-f2q615RqwcNlfyYPoTFjQ0jMY"; //"YOUR_KEY_HERE"; String baseURL = "http://ajax.googleapis.com/ajax/services/search/web?"; String terms = "bread+pudding"; //"paris+hilton"; 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)); // shows members String title = r.getString("title"); String titleNoF = r.getString("titleNoFormatting"); String url = r.getString("url"); String content = r.getString("content"); String cacheUrl = r.getString("cacheUrl"); //println(title); println(titleNoF); println(url); println(content); // parse me // or store me in an array } } catch(Exception e) { e.printStackTrace(); } } void draw() { // and draw me later }