google-images

Search for images using Google Images

  • 所有者: vadimdemedes/google-images
  • 平台:
  • 許可證:
  • 分類:
  • 主題:
  • 喜歡:
    0
      比較:

Github星跟蹤圖

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.

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

主要指標

概覽
名稱與所有者vadimdemedes/google-images
主編程語言JavaScript
編程語言JavaScript (語言數: 1)
平台
許可證
所有者活动
創建於2011-12-02 16:59:57
推送於2022-07-17 03:29:55
最后一次提交2017-02-27 21:19:07
發布數9
最新版本名稱v2.1.0 (發布於 2017-02-27 21:19:07)
第一版名稱0.0.5 (發布於 2012-02-20 22:13:54)
用户参与
星數306
關注者數12
派生數72
提交數39
已啟用問題?
問題數19
打開的問題數5
拉請求數9
打開的拉請求數2
關閉的拉請求數10
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?