spatie/googlesearch

此包已被废弃,不再维护。未建议替代包。

从Google自定义搜索引擎获取搜索结果

2.0.3 2016-10-05 07:09 UTC

This package is auto-updated.

Last update: 2020-01-17 14:14:57 UTC


README

Latest Version Build status SensioLabsInsight Quality Score StyleCI Total Downloads Software License

此包可以获取Google自定义搜索引擎付费版本的搜索结果。它返回一个包含搜索结果的数组。您需要了解如何设置Google自定义搜索引擎

Spatie是比利时安特卫普的一家网络设计公司。您可以在我们的网站上找到我们所有开源项目的概述在此

Laravel兼容性

Laravel googlesearch
4.2.x 1.x
5.x 2.x

Postcardware

您可以使用此包(它是MIT许可),但如果它进入您的生产环境,您需要向我们寄一张来自您家乡的明信片,注明您正在使用我们的哪个包。

我们的地址是:Spatie,Samberstraat 69D,2060 安特卫普,比利时。

最佳明信片将被发布在我们的网站开源页面。

安装

此包可以通过Composer安装。

composer require spatie/googlesearch

当使用Laravel时,您可以使用一个服务提供者。


// Laravel 5: config/app.php

'providers' => [
    '...',
    'Spatie\GoogleSearch\GoogleSearchServiceProvider'
];

GoogleSearch还附带了一个门面,它提供了一个方便的方式来调用类。


// Laravel 5: config/app.php

'aliases' => [
	...
	'GoogleSearch' => 'Spatie\GoogleSearch\Facades\GoogleSearch',
	...
]

您可以使用Artisan发布包的配置文件

php artisan vendor:publish --provider="Spatie\GoogleSearch\GoogleSearchServiceProvider"

此命令会在您的配置目录中创建一个文件,您可以在其中指定要使用的自定义搜索引擎的ID。

用法

以下是一个获取搜索结果的示例调用

/* 
  This function returns an array with keys
  
  "name"     // the name of the found page
  "url"      // the url of the found page
  "snippet"  // a little piece of text found on the page
*/

$searchResults = GoogleSearch::getResults('The meaning of life'); // is 42

如果没有找到结果,将返回一个空数组。

关于Spatie

Spatie是比利时安特卫普的一家网络设计公司。您可以在我们的网站上找到我们所有开源项目的概述在此