odannyc/google-image-search

此包的最新版本(v1.0.1)没有可用的许可信息。

您可以使用谷歌的新自定义搜索API查询谷歌图像。

v1.0.1 2016-08-24 22:31 UTC

This package is auto-updated.

Last update: 2024-09-07 05:33:55 UTC


README

您可以使用谷歌的新自定义搜索API查询谷歌图像。

ImageSearch::config()->apiKey('API Goes Here');
ImageSearch::config()->cx('CX Goes Here');

ImageSearch::search('civic'); // returns array of results

要求

您需要一个API密钥和一个CX字符串,这两个都可以在以下位置找到: https://developers.google.com/custom-search/docs/overview

安装

使用composer安装

composer require odannyc/google-image-search

用法

使用config方法设置API和CX字符串

use odannyc\GoogleImageSearch\ImageSearch;

ImageSearch::config()->apiKey('API Goes Here');
ImageSearch::config()->cx('CX Goes Here');

完成之后,使用search方法查询特定的文本字符串

ImageSearch::search('civic');

您还可以将一些过滤器作为第二个参数传递为一个数组。

ImageSearch::search('civic', ['imgSize' => 'large']);

过滤器列表可以在谷歌官方网站找到

https://developers.google.com/custom-search/json-api/v1/reference/cse/list

它将返回一个结果数组。图像特别位于items键中。