Question

I'm writing a program that requests images from Google Images.

I get a JSON object which I convert to an array. But for some reasons it always has only 4 images which sounds like a limit. And I want to disable it...

JSONArray results = json.getJSONObject("responseData").getJSONArray("results");
for(int j = 0; j < results.length(); j++) {
    String strurl = results.getJSONObject(j).getString("unescapedUrl");
    BufferedImage image = null;
    try {

        URL url = new URI(strurl).toURL();
        System.out.println("URL content type:"+url.openConnection().getContentType());
        URLConnection connection = url.openConnection();
        image = ImageIO.read(connection.getInputStream());
        } catch(MalformedURLException e) {
        e.printStackTrace();
        } catch(IOException e ) {
        e.printStackTrace();
        continue;
        } catch (URISyntaxException e) {
        e.printStackTrace();
    }
    // I display the image.
}

And the JSONArray results is always 3(I printed it out) not matter what the search keyword is.

Is there way to define the amount of results I want?

I'm desperate... I'll be grateful for any kind of answer, even a longshot.

Was it helpful?

Solution

It just seems that the page returns only 4 images. So I added start=number. Therefore I send multiple requests.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top