jbarbin/googlebooksbundle

一个基本的Symfony扩展包,提供了一个简单的方式来使用Google Books API。

dev-master 2018-02-09 21:55 UTC

This package is not auto-updated.

Last update: 2024-09-25 03:17:54 UTC


README

一个基本的Symfony扩展包,提供了一个简单的方式来使用Google Books API。

安装

步骤 1: 下载扩展包

打开命令行控制台,进入您的项目目录,并执行以下命令以下载此扩展包的最新稳定版本

$ composer require jbarbin/googlebooksbundle

此命令要求您全局安装Composer,如Composer文档中的安装章节所述。

步骤 2: 启用扩展包

然后,将扩展包添加到项目中的注册扩展包列表中,以在app/AppKernel.php文件中启用它

<?php
// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...

            new JBarbin\GoogleBooksBundle\JBarbinGoogleBooksBundle(),
        );

        // ...
    }

    // ...
}

步骤 3: 配置您的Google API密钥

首先,您需要在https://console.developers.google.com的Google开发者控制台中创建一个API密钥。您必须在项目中激活Google Books API并创建一个API密钥。

# app/services.yml


parameters:
    // ...
    jbarbin_googlebooks.google_api_key: ???????????????????????????

用法

通过标题或/和作者搜索书籍

// Use statement
use JBarbin\GoogleBooksBundle\GoogleAPI\Query;

// ...

$googleAPI = $this->get('jbarbin_googlebooks_api');
$api_key = $this->container->getParameter('jbarbin_googlebooks.google_api_key');
$query = new Query($api_key);

// Search by title
$query->setTitle('book title');

// Search by author
$query->setTitle('book author');

// Get results
$books = $googleAPI->searchBook($query);