jfkz/google-custom-search-api 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

jfkz/google-custom-search-api

Composer 安装命令:

composer require jfkz/google-custom-search-api

包简介

Google Custom Search api

README 文档

README

The aim of this project is to create a well structured PHP library for accessing Google APIs available through the Google APIs console.

Currently the library enables you to interact programmatically with the following Google APIs,

Requirements

  • The library is only supported on PHP 5.3.0 and up.
  • It has been assumed an autoloader will be present. If you require one, you can find one here.
  • Each API requires an API key, which you can get from the Google APIs console.

Installation

Simply download the library and add the src folder to your project.

Usage

Note: More extensive documentation will be made available at a later date.

Custom Search API

Note: As well as an API key, the Google Custom Search API v1 also requires either a Google Custom Search ID or specification URL.

The following makes a simple Google Custom Search API v1 request,

$apiClient = new \Google\Api\CustomSearch();
$apiClient->setApiKey('INSERT_YOUR_API_KEY_HERE');
$apiClient->setCustomSearchEngineId('INSERT_YOUR_CUSTOM_SEARCH_ENGINE_ID_HERE');
$apiClient->setQuery('flowers');

$response = $apiClient->executeRequest();

To get the results from the $response,

if ($response->isSuccess())
{
    foreach($response->getData()->getItems() as $item)
    {
        echo $item->getHtmlTitle(), ' - <a href="', $item->getLink(), '">', $item->getDisplayLink(), '</a><br />';
    }
}

Translate API

The following makes a simple Google Translate API v2 request,

$apiClient = new \Google\Api\Translate();
$apiClient->setApiKey('INSERT_YOUR_API_KEY_HERE');
$apiClient->addSourceText('The quick brown fox jumps over the lazy dog.');
$apiClient->setTargetLanguage('fr');

$response = $apiClient->executeRequest();

To get the translations from the $response,

if ($response->isSuccess())
{
    foreach($response->getData()->getTranslations() as $translation)
    {
        echo $translation->getTranslatedText(), '<br />';
    }
}

Testing

To run the tests, make sure you have PHPUnit 3.6.0 and up installed, and just run the following in the project root,

phpunit

统计信息

  • 总下载量: 488
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 13
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2019-11-05

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固