Giter Club home page Giter Club logo

google-images's Introduction

google-images Build Status

Search images using Google Custom Search Engine API.

Installation

$ npm install --save google-images

Usage

Note: You'll need to set up your own Google Custom Search Engine to execute queries.

const GoogleImages = require('google-images');

const client = new GoogleImages('CSE ID', 'API KEY');

client.search('Steve Angello')
	.then(images => {
		/*
		[{
			"url": "http://steveangello.com/boss.jpg",
			"type": "image/jpeg",
			"width": 1024,
			"height": 768,
			"size": 102451,
			"thumbnail": {
				"url": "http://steveangello.com/thumbnail.jpg",
				"width": 512,
				"height": 512
			}
		}]
		 */
	});

// paginate results
client.search('Steve Angello', {page: 2});

// search for certain size
client.search('Steve Angello', {size: 'large'});

API

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).

Client(engineId, apiKey)

engineId

Type: string

The identifier for a Custom Search Engine to use.

apiKey

Type: string

The credentials for accessing Google's API.

Instance

.search(query, option)

Perform an image search for query.

query

Type: string

The search terms to use for finding images. Identical to those you would use in a web search.

option

Type: object

page

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.

size

Type: string

The size of images to search. E.g. medium or xxlarge.

type

Type: string

The category of images to search. E.g. face or photo.

dominantColor

Type: string

The dominant color to search for. E.g. yellow or purple.

colorType

Type: string

The category of color spectrums to search. E.g. gray or color.

safe

Type: string

The heuristic level to use for filtering out explicit content using SafeSearch. E.g. off or high.

Set up Google Custom Search Engine

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:

1. Create a Google Custom Search Engine

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.

2. Enable Image Search

In your search engine settings, enable "Image search":

3. Set up a Google Custom Search Engine API

Register a new app and enable Google Custom Search Engine API here: Google Developers Console. Make a note of the API key.

License

MIT © Vadim Demedes

google-images's People

Contributors

4lador avatar davidyen1124 avatar mingstar avatar mkazantsev avatar muniftanjim avatar sholladay avatar unixpickle avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

google-images's Issues

Doesn't return anything at all

Set up everything as documented, however search just returns an empty array. Don't bother using since this project seems to be dead anyway.

"PassThrough is not a constructor" error

Hi, thanks for this helpful module.
I'm getting a "PassThrough is not a constructor" error from 'Webpack internal'. All I'm currently doing is testing the modules query code out to see if I can console log any image data received. I'm using the sample block of code provided.

I've attached screen-shots of the error I'm getting, the code the error refers to, and my React code.
The error could be stemming from the 'get-stream' modules 'buffer-stream.js' file since I've received a similar error from this file.

I thought it might have to do with me not having proper dependencies installed for the google-images module. I've installed and uninstalled GOT, fs, querystring, get-stream, etc modules. At this point I feel like I've exhausted all dependency combinations. No luck on Stack Overflow yet either.

Are any of your familiar with this error or can you guide me in the right direction on what could be causing it?
Thanks

passthroughnotconstructor

passthrougherror_bufferstream

passthroughnotconstructorcode

Turning on safe search

I'm trying to turn on safe search but it doesn't seem to be working. Not sure if its the format or something with the lib, either way, help would be much appreciated.

Code:

client.search(queryText,{
    	safe: 'high',
    	page: 1
    })
    .then(function (images) {

        console.log(images);
        res.json(
            images
        );

    })

additional documentation

Hi there!
I followed all of your set up instructions. Just curious, I'm trying to use this to get a string link to a random image from a google search query from the first page of the results. Just curious if you have any tips on how to access this once the search is made. Thanks!

Webpack Error: Module not found

I tried everything like

 const GoogleImages = require('google-images');
 window.GoogleImages = require('google-images');
 import GoogleImages from 'google-images';

Nothing works. I get the error:

 ERROR in ./node_modules/google-images/node_modules/got/index.js
 Module not found: Error: Can't resolve './package' in 
 '/Users/shadrix/Dropbox/Business/insta/Website_W_Laravel/insta/node_modules/google-images/node_modules/got'
  @ ./node_modules/google-images/node_modules/got/index.js 19:12-32
  @ ./node_modules/google-images/index.js
  @ ./resources/assets/js/bootstrap.js
  @ ./resources/assets/js/app.js
  @ multi ./resources/assets/js/app.js ./resources/assets/sass/app.scss

setImmediate is not defined

The bug
Just letting you know that you're using setImmediate in got/index.js, which throws the following error: ReferenceError: setImmediate is not defined

setImmediate() is a non-standard API and shouldn't be used in frontend code.

How to fix
Simply just exchanging it with setTimeout(func, 0);

For users in the interim
Users can get around this by adding the following within your html :

<script>
  const setImmediate = (func)=>{setTimeout(func,0001)};
</script>
``

Strange fs error

stream.js:94
      throw er; // Unhandled stream error in pipe.
            ^
Error: ENOSPC, write
  at Error (native)

It was a sequence of requests, then pause, then again and after ~hour of idle, it has appeared.
The trouble is that it's fatal. I'd like to add try blocks, but I cannot easily figure it out.
Hope, you'll help, but I'm going to struggle it anyway.

Authentication error caused by changing % to %25 in CSE_ID

My CSE_ID contains a % among many numbers, like 09184%3A. This gets changed into URL format into %25, which is how it's logged into the console for the error message, saying that there is a 400 HTTP error, and when I copy the url from the console and use it in the browser, the same happens. If I change the %25 for % in the address, it resolves into the proper image search successfully. I'm going to try to fix this myself on my end, but I think that it would be good if the project code had a fix for it too.

For illustation purposes, I'll leave the JSON response for the error, which is very vague:

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "invalid",
    "message": "Invalid Value"
   }
  ],
  "code": 400,
  "message": "Invalid Value"
 }
}

(it is explained online that this is may be caused by authentication errors, which is the verfied case here)

Returns zero images

I was using this package successfully earlier this year. And now I've started using it again (with the same app and with no changes to the code) but it seems to have stopped returning images.

I'm running this script:

googleSearch.search( 'query', function ( err, images ) {
    ...
});

But images is always returned as an empty array and err is returned as false. Is it still working for anyone else? I can't think why it would have just stopped.

I've updated the package to the latest version: 0.1.4

Scraping option

Not sure which way this library is learning, but you can get a hard scrape of the google images with the follow script. This means that it will visit the images homepage and scrape for images from there.

The script is short and can be found here. https://github.com/bluejamesbond/cs373-idb/blob/gh-pages/scripts/google/images.js (made for educational purposes)

It would be interesting to see you have two options: (1) the rest protocol and the (2) hard scrape format. The hard scrape if used correctly (as to not trigger the google scrape detector) will allow you to get unlimited images.

Error: Cannot read property 'map' of undefined

If the query contains characters used by google search like '-', the module throw a TypeError

TypeError: Cannot read property 'map' of undefined
    at Client._buildResponse (E:\Dev\MisterGoodNews\AuthorBot\mgn-authorbot\node_modules\google-images\index.js:60:23)
    at process._tickCallback (internal/process/next_tick.js:103:7)

Maybe we could delete this character from the string in the search function ?

I'll create a pull request with the workaround :)

Order of results?

I performed a search with the name of a novel as my query, and the first result was a pornographic image. When I manually enter this search query on Google images, I do not see this pornographic image anywhere in the search results. This is not a 'safe search' related issue.

How are the results being selected?
What determines the order of the results?

Ideally, I would like for the results to be the same as those which are visible when manually searching Google Images...

Got doesn't report errors

When there is an error (i.e., I was over my quota for searches) it is not reported to the console.

The 'got' call should look more like this:

got('todomvc.com')
    .then(response => {
        console.log(response.body);
        //=> '<!doctype html> ...' 
    })
    .catch(error => {
        console.log(error.response.body);
        //=> 'Internal server error ...' 
    });

https://www.npmjs.com/package/got

npm install google-images --save

hi vadimdemedes, thanks for this great work~
I encounter some problems when using your code. I couldn't install google-images any way, i have tried countless way provided by google, but it didn't work. Is there any key point about this topic?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.