I changed the web search api to image search api ie. http://ajax.googleapis.com/ajax/services/search/images
I wish to include ability to search images in my application. So for that purpose what should I write ther. I think I need more help.Can you please suggest me some URL that will work? On May 5, 6:54 pm, Jeremy Geerdes <[email protected]> wrote: > Your HTTP_REFERER header needs to be a valid URL. For web applications, this > is the URL to the application. For non-web apps, I generally recommend using > the URL of a page that provides a basic description of your application and > information for contacting you should the need arise. > > Jeremy R. Geerdes > Generally Cool Guy > Des Moines, IA > > For more information or a project quote: > [email protected] > > If you're in the Des Moines, IA, area, check out Debra Heights Wesleyan > Church! > > On May 5, 2011, at 8:50 AM, sapna jain wrote: > > > > > > > > > Thanks jeremy for reply. > > But I am not getting what should I provide at that place? > > Can you please give me some example? > > > On May 5, 6:24 pm, Jeremy Geerdes <[email protected]> wrote: > >> The first thing I see is the HTTP_REFERER being set to google.com. I would > >> not be surprised if the API threw an error on that. > > >> Jeremy R. Geerdes > >> Generally Cool Guy > >> Des Moines, IA > > >> For more information or a project quote: > >> [email protected] > > >> If you're in the Des Moines, IA, area, check out Debra Heights Wesleyan > >> Church! > > >> On May 5, 2011, at 7:09 AM, sapna jain wrote: > > >>> Hello folks, > >>> I wish to use google search API in my application made in procssing. > >>> When I tried to run following code: > > >>> import java.io.BufferedReader; > >>> import java.io.InputStreamReader; > >>> import java.net.URL; > >>> import java.net.URLConnection; > >>> import java.net.URLEncoder; > >>> import org.json.JSONArray; // JSON library > >>> fromhttp://www.json.org/java/ > >>> import org.json.JSONObject; > > >>> // Put your website here > >>> private final String HTTP_REFERER = "http://www.google.com/"; > > >>> void setup() > >>> { > >>> size(700,700); > >>> makeQuery("questio verum"); > >>> //makeQuery("info:http://frankmccown.blogspot.com/"); > >>> //makeQuery("site:frankmccown.blogspot.com"); > >>> } > > >>> void makeQuery(String query) { > > >>> System.out.println(" Querying for " + query); > > >>> try > >>> { > >>> // Convert spaces to +, etc. to make a valid URL > >>> query = URLEncoder.encode(query, "UTF-8"); > >>> // note: you can change the start index here. > >>> URL url = new URL("http://ajax.googleapis.com/ajax/services/search/ > >>> web?start=0&rsz=large&v=1.0&q=" + query+"&key=ABQIAAAAIyAHL0_ENlWOch- > >>> kfrCVeRSsTL4WIgxhMZ0ZK_kHjwHeQuOD4xRWsfidvm2jtqgzKiXTEJnQWOxhnQ"); > >>> println("hello before"); > > >>> URLConnection connection = url.openConnection(); > >>> connection.addRequestProperty("Referer", HTTP_REFERER); > > >>> // Get the JSON response > >>> String line; > >>> StringBuilder builder = new StringBuilder(); > >>> // println("hello"); > >>> BufferedReader reader = new BufferedReader(new > >>> InputStreamReader(connection.getInputStream())); > >>> while((line = reader.readLine()) != null) { > >>> builder.append(line); > >>> } > > >>> String response = builder.toString(); > >>> JSONObject json = new JSONObject(response); > > >>> System.out.println("Total results = " + > > >>> json.getJSONObject("responseData").getJSONObject("cursor").getString("estimatedResultCount")); > > >>> JSONArray ja = > >>> json.getJSONObject("responseData").getJSONArray("results"); > > >>> System.out.println(" Results:"); > >>> for (int i = 0; i < ja.length(); i++) { > >>> System.out.print((i+1) + ". "); > >>> JSONObject j = ja.getJSONObject(i); > >>> System.out.println(j.getString("titleNoFormatting")); > >>> System.out.println(j.getString("url")); > >>> } > >>> } > >>> catch (Exception e) { > >>> System.err.println("Something went wrong..."); > >>> e.printStackTrace(); > >>> } > >>> } > > >>> java.net.connect exception was thrown.Complete description is as: > > >>> Something went wrong... > >>> java.net.ConnectException: Connection refused: connect > >>> at java.net.PlainSocketImpl.socketConnect(Native Method) > >>> at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333) > >>> at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java: > >>> 195) > >>> at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182) > >>> at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366) > >>> at java.net.Socket.connect(Socket.java:529) > >>> at java.net.Socket.connect(Socket.java:478) > >>> at sun.net.NetworkClient.doConnect(NetworkClient.java:163) > >>> at sun.net.www.http.HttpClient.openServer(HttpClient.java:394) > >>> at sun.net.www.http.HttpClient.openServer(HttpClient.java:529) > >>> at sun.net.www.http.HttpClient.<init>(HttpClient.java:233) > >>> at sun.net.www.http.HttpClient.New(HttpClient.java:306) > >>> at sun.net.www.http.HttpClient.New(HttpClient.java:323) > >>> at > >>> sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnectio... > >>> 860) > >>> at > >>> sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java: > >>> 801) > >>> at > >>> sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java: > >>> 726) > >>> at > >>> sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.... > >>> 1049) > >>> at sketch_may03a.makeQuery(sketch_may03a.java:67) > >>> at sketch_may03a.setup(sketch_may03a.java:43) > >>> at processing.core.PApplet.handleDraw(Unknown Source) > >>> at processing.core.PApplet.run(Unknown Source) > >>> at java.lang.Thread.run(Thread.java:619) > > >>> Can anyone here help me resolve the problem? > > >>> -- > >>> You received this message because you are subscribed to the Google Groups > >>> "Google AJAX APIs" group. > >>> To post to this group, send email to > >>> [email protected]. > >>> To unsubscribe from this group, send email to > >>> [email protected]. > >>> For more options, visit this group > >>> athttp://groups.google.com/group/google-ajax-search-api?hl=en. > > > -- > > You received this message because you are subscribed to the Google Groups > > "Google AJAX APIs" group. > > To post to this group, send email to > > [email protected]. > > To unsubscribe from this group, send email to > > [email protected]. > > For more options, visit this group > > athttp://groups.google.com/group/google-ajax-search-api?hl=en. -- You received this message because you are subscribed to the Google Groups "Google AJAX APIs" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-ajax-search-api?hl=en.
