23

Im using the google APIs ajax below to get images for particular search terms. This is being done in a WinForms app.

The below link seems to work, but it only returns 4 results (via JSON)

Anyone know how to coax more out of it?

http://ajax.googleapis.com/ajax/services/search/images?v=1.0&q=Apple+Cake

Obviously there has to be another parameter to request more or page through the results, but I can't seem to figure it out? Anyone know?

skaffman
  • 398,947
  • 96
  • 818
  • 769
Jason
  • 11,435
  • 24
  • 77
  • 131
  • The same question: [how to get ALL google search results using api](http://stackoverflow.com/questions/14055197/how-to-get-all-google-search-results-using-api). It should be merged I think. – kenorb Nov 22 '14 at 20:39
  • The bad part is that there's no such API anymore. – polkovnikov.ph Dec 12 '16 at 20:28

7 Answers7

32

I believe the only way to do that is to make multiple calls to the webservice specifying the 'start' parameter.

http://ajax.googleapis.com/ajax/services/search/images?v=1.0&q=Apple+Cake&start=4

The start parameter is the 0-based index into the search results. So in this example, it would return images 4..7.

You can also add the parameter rsz=[1-8]. The default value is 4. That's why you're getting 4 results per request. Here's a link:
http://code.google.com/apis/imagesearch/v1/jsondevguide.html#basic_query

Remi Guan
  • 21,506
  • 17
  • 64
  • 87
rforte
  • 1,167
  • 1
  • 11
  • 21
13

You can use "&rsz=8", refer below...

http://ajax.googleapis.com/ajax/services/search/video?q=SpongeBob%20Full&v=1.0&start=8&rsz=8

user2862302
  • 131
  • 1
  • 3
5

For those of you wondering how to do this, there are quite a few ways. One would be to run a looping query based on a certain event. So, for instance...

var biebresults = [], start = 0;
function getBieb(startNumber){
    $.getJSON("https://ajax.googleapis.com/ajax/services/search/images?v=1.0&q=Justin%20Bieber&start="+startNumber+"&callback=?", function(results){
        biebresults.push(results.responseData.results);
        if(biebresults.length < 538){
            start = start + 4;
            getBieb(start);
        } else {
            // Do something with your billion bieb images.
        }
    });
}
getBieb(start);

This particular bit of code (using jQuery, btw) will go and grab the first four images of your favorite pop star. From here it counts the number of results and if it isn't enough, it will run getBieb again, except this time with the startNumber argument increased.

2

Google Feed provides an optional method, where you can specify the no. of results that you want to get. If you don't specify this method the default no. of results you get is 4, however to get more no. of feeds you can specify this optional method as follows;

feed.setNumEntries(int);

e-g: feed.setNumEntries(16); // will return 16 results.

.setNumEntries(num) sets the number of feed entries loaded by this feed to num. By default, the Feed class loads four entries.

.setNumEntries() has no return value.

https://developers.google.com/feed/v1/reference#setNumEntries

defau1t
  • 10,593
  • 2
  • 35
  • 47
1

Use the below to get 8 results

 $url = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&rsz=large&start=0&q=".$query; 

After that put the for loop then you well be able to get 64 Results

 <?php

         $search =str_replace(' ', '+', @$_GET["q"]);

            $query = $search;
            for ($i=1; $i < 100; $i+8) { 



            $url = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&rsz=8&start=".$i."&q=".$query;
            $body = file_get_contents($url);
            $json = json_decode($body);

            for($x=0;$x<count($json->responseData->results);$x++){

            echo "<b>Result ".($x+1)."</b>";
            echo "<br>URL: ";
            ?>
            <a href="<?php echo $json->responseData->results[$x]->url; ?>" target="_blank"> <?php echo $json->responseData->results[$x]->url; ?> </a>
            <?php
            echo "<br>VisibleURL: ";
            ?>
            <a href="http://<?php echo $json->responseData->results[$x]->visibleUrl; ?>" target="_blank"> <?php echo $json->responseData->results[$x]->visibleUrl; ?> </a>
            <?php

            echo "<br>Title: ";
            echo $json->responseData->results[$x]->title;
            echo "<br>Content: ";
            echo $json->responseData->results[$x]->content;
            echo "<br><br>";              

        }
            $i+=8;
         }

?>

0

you can get more if you want

public static void main(String[] args) throws UnsupportedEncodingException, IOException {
String google = "http://www.google.com/search?q=";
String search = "dinh la thang site:dantri.com.vn";
String charset = "UTF-8";
String userAgent = "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.4; en-US; rv:1.9.2.2) Gecko/20100316 Firefox/3.6.2"; // Change this to your company's name and bot homepage!
System.out.println(URLEncoder.encode(search, charset));
int i=1;
while(i<100){
    Elements links = Jsoup.connect(google + URLEncoder.encode(search, charset)+"&start="+i).userAgent(userAgent).get().select("li.g>h3>a");

    for (Element link : links) {
    String title = link.text();
    //System.out.println(link.toString());
    String url = link.absUrl("href"); // Google returns URLs in format "http://www.google.com/url?q=<url>&sa=U&ei=<someKey>".
    //System.out.println(url);
    url = URLDecoder.decode(url.substring(url.indexOf('=') + 1, url.indexOf('&')), "UTF-8");

    if (!url.startsWith("http")) {
        continue; // Ads/news/etc.
    }
    System.out.println(i+"Title: " + title);
    System.out.println("URL: " + url);

    } i=i+10;
    }
}
}
bummi
  • 27,123
  • 14
  • 62
  • 101
vuhoanghiep1993
  • 715
  • 1
  • 8
  • 15
0

Visit... this link about method you need: setResultSetSize(num)

mdromed
  • 49
  • 7