Hi,
I'm working in Java (Eclipse Platform).
I'm a new user of Google Ajax APIs.
I need to get results from google when giving a query.
But I was surprised that I got only four results. I don't know how to
get more results .
This is the code (I developed it using :
http://code.google.com/intl/fr/apis/websearch/docs/#The_Basics : the
JAVA Access Section) :

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;


import net.sf.json.*;


public class GoogleQuery {

private final String HTTP_REFERER = "http://
www.mygooglesearchssite.com/AsmaSite/";

public GoogleQuery() {
makeQuery("life");
}

private void makeQuery(String query) {

System.out.println("\nQuerying for " + query);

try
{
// Convert spaces to +, etc. to make a valid URL
query = URLEncoder.encode(query, "UTF-8");

URL url = new URL(
            "https://ajax.googleapis.com/ajax/services/search/web?v=1.0&";
            + "q="+query
            +"&key=MYKEY&userip=MYUSERIP");

URLConnection connection = url.openConnection();
connection.addRequestProperty("Referer", HTTP_REFERER);

// Get the JSON response
String line;
StringBuilder builder = new StringBuilder();
BufferedReader reader = new BufferedReader(
new InputStreamReader(connection.getInputStream()));
while((line = reader.readLine()) != null) {
        System.out.println(line);
        builder.append(line);
}

String response = builder.toString();
JSONObject json = new JSONObject(builder.toString());
JSONObject jsonObject = new JSONObject();

System.out.println("Total results = " +
json.getJSONObject("responseData")
.getJSONObject("cursor")
.getString("estimatedResultCount"));

JSONArray ja =
json.getJSONObject("responseData").getJSONArray("results");

System.out.println("\nResults:");
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();
}
}

public static void main(String args[]) {
new GoogleQuery();
}
}

I need your help.
Regards,
Asma

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