devdojo / google-image-search

该包最新版本(0.2)没有提供许可证信息。

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

0.2 2021-03-14 17:32 UTC

This package is auto-updated.

Last update: 2024-09-15 03:44:45 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 devdojo/google-image-search

使用方法

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

use DevDojo\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键中。