0

By default, it gives 10 results. How can I have n number of results?

Here is my code so far (pretty much same as in their example):

var google = require('googleapis');
var customsearch = google.customsearch('v1');

const CX = '***';   // search engine ID
const API_KEY = '***';
const SEARCH = '***';

customsearch.cse.list({ cx: CX, q: SEARCH, auth: API_KEY }, function(err, resp) {
    if (err) {
        console.log('An error occured', err);
        return;
    }

    // Got the response from custom search
    console.log('Result: ' + resp.searchInformation.formattedTotalResults);

    if (resp.items && resp.items.length > 0) {
        var l = resp.items.length;
        console.log('# of results: ' + l); // this is always 10

        console.log('Results:', resp.items);
        for(var i=0; i<l; i++){
            console.log('Result # ' + (i+1) + ': ', resp.items[i]);
        }
    }
});

UPDATE: What if I want to access 238 results? I know that I can loop through and get 10 results each time, but it doesnt allow me to go past 99 results.

Rahul Desai
  • 15,242
  • 19
  • 83
  • 138

1 Answers1

2

you can use the 'num' option.

customsearch.cse.list({ cx: CX, q: SEARCH, auth: API_KEY, num: NUMBER }, function(err, resp) {
    ...
});

NUMBER should be an integer between 1 and 10, inclusive.

you can find all options there - CSE: list

  • I do not think you understood my question. What if I want to access 238 results? I know that I can loop through and get 10 results each time, but it doesnt allow me to go past 99 results. – Rahul Desai Nov 02 '15 at 20:24
  • You can use a combination of `num` and `start` parameter – Hartator Apr 09 '18 at 21:52