Search images using Google Custom Search
$ npm i image-search-google
Note: You'll need to set up your own Google Custom Search Engine to execute queries.
const imageSearch = require('image-search-google');
const client = new imageSearch('CSE ID', 'API KEY');
const options = {page:1};
client.search('APJ Abdul kalam', options)
.then(images => {
/*
[{
'url': item.link,
'thumbnail':item.image.thumbnailLink,
'snippet':item.title,
'context': item.image.contextLink
}]
*/
})
.catch(error => console.log(error););
// search for certain size
client.search('Mahatma Gandhi', {size: 'large'});
// search for certain type
client.search('Indira Gandhi', {type: 'face'});
Please see Google's API documentation for details on the option and response properties and their possible values. Note that the option names used here may differ slightly (e.g. no img
prefix).
Google deprecated their public Google Images API, so to search for images you need to sign up for Google Custom Search Engine. Here are the steps you need to do:
You can do this here: https://cse.google.com/cse.
Do not specify any sites to search but instead use the "Restrict Pages using Schema.org Types" under the "Advanced options".
For the most inclusive set, use the Schema: Thing
. Make a note of the CSE ID.
In your search engine settings, enable "Image search".
Register a new app and enable Google Custom Search Engine API here: Google Developers Console. Make a note of the API key.
Type: string
The identifier for a Custom Search Engine to use.
Type: string
The credentials for accessing Google's API.
Type: object
Type: number
Default: 1
The range of results to return. Useful because often results cannot be returned in a single response. Note that it is a one-based unsigned integer. E.g. page 1
has the first 10 results, page 2
has the next set of 10, etc.
Type: string
The size of images to search. E.g. medium
or xxlarge
.
Type: string
The category of images to search. E.g. face
or photo
.
Type: string
The dominant color to search for. E.g. yellow
or purple
.
Type: string
The category of color to search. E.g. gray
or color
.
Isc ©