Google AJAX API - How do I get more than 4 Results?
Asked Answered
P

7

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?

Pohl answered 1/2, 2011 at 22:42 Comment(2)
The same question: how to get ALL google search results using api. It should be merged I think.Clique
The bad part is that there's no such API anymore.Cimon
V
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

Venue answered 1/2, 2011 at 22:54 Comment(6)
Awesome, exactly what I wanted. ThanksPohl
This seems to be deprecated in 2014 (see developers.google.com/web-search/docs). What would be the current solution now ?Janniejanos
Link says last day of operation was in Sept 2014, but it still seems to work. Maybe this used to be more powerful, and they're just leaving up a basic version.Retentive
can we get results more than 8Gossipmonger
What would be an alternative API for this since it's deprecated?Mcelroy
This API is deprecated, Custom Search API should be used now instead developers.google.com/custom-searchDeadlock
K
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

Keyte answered 9/10, 2013 at 10:17 Comment(1)
Nice, how did you know this btw?Algerian
S
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.

Sekofski answered 14/5, 2011 at 6:29 Comment(1)
jquery is taboo. Do not start talking about jquery unless it has already been spake on the page.Algerian
R
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

Rohde answered 3/3, 2013 at 1:57 Comment(0)
G
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;
         }

?>

Guajardo answered 29/4, 2015 at 6:19 Comment(2)
Could you please elaborate more your answer adding a little more description about the solution you provide?Cluster
yas put the for mean the make it nested loop... and u well get more resultsGuajardo
A
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;
    }
}
}
Angeli answered 10/9, 2014 at 16:46 Comment(0)
T
0

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

Therapsid answered 18/12, 2014 at 20:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.