abbaiakram / google-custom-search
使用谷歌API,我们可以搜索谷歌中的任何关键词,并且可以将此集成到我们的系统中
dev-main
2022-07-05 14:47 UTC
Requires
- php: >=7.2
- ext-curl: ^7.1
- composer/composer: 1.0.*@dev
This package is auto-updated.
Last update: 2024-09-05 19:45:08 UTC
README
搜索请求元数据
搜索元数据包括
url property, which has information about the OpenSearch template used for the results returned in this request.
queries property, which is an array of objects describing the characteristics of possible searches. The name of each object in the array is either the name of an OpenSearch query role or one of the two custom roles defined by this API: previousPage and nextPage . Possible query role objects include:
request: Metadata describing the query for the current set of results.
This role is always present in the response.
It is always an array with just one element.
nextPage: Metadata describing the query to use for the next page of results.
This role is not present if the current results are the last page. Note: This API returns up to the first 100 results only.
When present, it is always a array with just one element.
previousPage: Metadata describing the query to use for the previous page of results.
Not present if the current results are the first page.
When present, it is always a array with just one element.
要求
- PHP版本7.2或更高
简单安装
使用Composer安装
要使用Composer安装,只需要求此包的最新版本。
composer require abbaiakram/google-custom-search
require_once("searchEngine.php");
// 实例化类 $client = new SearchEngine(); // 将API密钥作为参数传递或留空以使用默认API。 $client->setEngine('google.ae'); $results = $client->search(['dubai']);
// 要遍历结果,可以这样做,
if ($results[0]->items) { foreach($results[0]->items as $result) {
print $result->title. '<br />';
print $result->htmlTitle. '<br />';
print $result->link. '<br />';
echo $result->htmlSnippet. '<br />';
print $result->formattedUrl."<br><br>";
}
}
// 输出结果分页和完整数据 print '
'; print_r($results[0]->items); print '';