I am trying to get the following example to work but I keep getting the
following error.



*java -cp googleapi.jar com.google.soap.search.GoogleAPIDemo mykey cached
http://www.yahoo.com*

Parameters:

Client key =
ABQIAAAA1x3Qiu3bqQlQI_3RdZC7HhT2yXp_ZAY8_ufC3CFXhHIE1NvwkxTg_7MpjBDqrWoaPE9wRuX4TfOzjA

Directive = cached

Args = http://www.yahoo.com

Cached page:

============

The call to the Google Web APIs failed:

com.google.soap.search.GoogleSearchFault: [SOAPException:
faultCode=SOAP-ENV:Protocol; msg=Unsupported response content type
"text/html; charset=UTF-8", must be: "text/xml". Response was:



<html><head>

<meta http-equiv="content-type" content="text/html;charset=utf-8">

<title>404 Not Found</title>

<style><!--

body {font-family: arial,sans-serif}

div.nav {margin-top: 1ex}

div.nav A {font-size: 10pt; font-family: arial,sans-serif}

span.nav {font-size: 10pt; font-family: arial,sans-serif; font-weight: bold}

div.nav A,span.big {font-size: 12pt; color: #0000cc}

div.nav A {font-size: 10pt; color: black}

A.l:link {color: #6f6f6f}

A.u:link {color: green}

//--></style>

<script><!--

var rc=404;

//-->

</script>

</head>

<body text=#000000 bgcolor=#ffffff>

<table border=0 cellpadding=2 cellspacing=0 width=100%><tr><td rowspan=3
width=1% nowrap>

<b><font face=times color=#0039b6 size=10>G</font><font face=times
color=#c41200 size=10>o</font><font face=times color=#f3c518
size=10>o</font><font face=times color=#0039b6 size=10>g</font><font
face=times color=#30a72f size=10>l</font><font face=times color=#c41200
size=10>e</font>&nbsp;&nbsp;</b>

<td>&nbsp;</td></tr>

<tr><td bgcolor="#3366cc"><font face=arial,sans-serif
color="#ffffff"><b>Error</b></td></tr>

<tr><td>&nbsp;</td></tr></table>

<blockquote>

<H1>Not Found</H1>

The requested URL <code>/search/beta2</code> was not found on this server.

<p>

</blockquote>

<table width=100% cellpadding=0 cellspacing=0><tr><td bgcolor="#3366cc"><img
alt="" width=1 height=4></td></tr></table>

</body></html>

]

*Can someone help me out with this?*
*Also does anyone have a working example of a java application using the
google ajax based search?*  * Do I have to have a key in order for this to
work?  I was not clear on that.*



I have tried the following with no luck as well.

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

import java.net.MalformedURLException;

import java.net.URL;

import java.net.URLConnection;

import org.json.*;





public class SearchTestGoogle {

/**

* @param args

* @throws JSONException

* @throws IOException

*/

public static void main(String[] args) throws JSONException, IOException {

// TODO Auto-generated method stub

// This example request includes an optional API key which you will need to

// remove or replace with your own key.

// Read more about why it's useful to have an API key.

// The request also includes the userip parameter which provides the end

// user's IP address. Doing so will help distinguish this legitimate

// server-side traffic from traffic which doesn't come from an end-user.

// +
"q=Paris%20Hilton&key=CSIZCKFQFHLdm6TJhHUGIJBYZEA08ZGQ&userip=192.168.1.104");


URL url = new URL(

"http://ajax.googleapis.com/ajax/services/search/web?v=1.0&";

+ "q=http://www.yahoo.com&userip=192.168.1.104";);

URLConnection connection = url.openConnection();

connection.addRequestProperty("Referer", "http://www.yahoo.com";);

String line;

StringBuilder builder = new StringBuilder();

BufferedReader reader = new BufferedReader(new
InputStreamReader(connection.getInputStream()));

while((line = reader.readLine()) != null) {

builder.append(line);

}

JSONObject json = new JSONObject(builder.toString());

System.out.println(json.toString());

// now have some fun with the results...

}
}

-- 
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.

Reply via email to