angelleger/google-books 问题修复 & 功能扩展

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

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

angelleger/google-books

Composer 安装命令:

composer require angelleger/google-books

包简介

Package for interacting with the Google Books API

README 文档

README

Build Status Scrutinizer code quality Packagist Gitter

php-google-books

Simple PHP package for working with the Google Books API. With Laravel5 integration. Doesn't yet support authentication, so it only works with public data. PRs are welcome.

Install using Composer

Make sure you have Composer installed, then run

composer require scriptotek/google-books

in your project directory to get the latest stable version of the package.

Usage

Start by creating a new client:

require_once('vendor/autoload.php');
use Angelleger\GoogleBooks\GoogleBooks;

$books = new GoogleBooks(['key' => 'YOUR_API_KEY_HERE']);

Note that you can also use the API without specifying an API key, but you will then get a lower request quota. A UsageLimitExceeded exception is thrown when you reach the quota.

Working with volumes

Getting a single volume by id:

$volume = $books->volumes->get('kdwPAQAAMAAJ');

or by ISBN:

$volume = $books->volumes->byIsbn('0521339057');

Search:

foreach ($books->volumes->search('Hello world') as $vol) {
    echo $vol->title . "\n";
}

Note that the search() method returns a generator that automatically fetches more results until the result list is depleted. If there are thousands of results this will of course take a long time to fetch, so you probably want to define a limit. Limits can be defined as an option: ['maxResults' => 10] inside the GoogleBooks class.

Working with bookshelves

Getting a single bookshelf by user id and shelf id:

$shelf = $books->bookshelves->get('113555231101190020526', '1002');

List the public bookshelves of a user, and their volumes:

foreach ($books->bookshelves->byUser('113555231101190020526') as $shelf) {
    echo "<h2>$shelf->title</h2>\n";
    echo "<ul>\n";
    foreach ($shelf->getVolumes() as $vol) {
        echo "  <li>$vol->title</li>\n";
    }
    echo "</ul>\n";
}

Laravel 5 integration

This project ships with a service provider that you can add to the $providers array in your config/app.php:

Angelleger\GoogleBooks\GoogleBooksServiceProvider::class,

There's also a facade you can add to the $aliases array if you like:

'GoogleBooks' => Angelleger\GoogleBooks\GoogleBooksFacade::class,

Run

$ php artisan vendor:publish --provider="Angelleger\GoogleBooks\GoogleBooksServiceProvider"

to create the config/googlebooks.php configuration file.

Troubleshooting

If you get 403 Forbidden with

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "unknownLocation",
    "message": "Cannot determine user location for geographically restricted operation."
   }
  ],
  "code": 403,
  "message": "Cannot determine user location for geographically restricted operation."
 }
}

it means the Books API failed to locate you based on your ip address. Fix this by specifying the 2 letter ISO639 country code manually using the country option to the constructor:

$books = new GoogleBooks(['country' => 'NO']);

angelleger/google-books 适用场景与选型建议

angelleger/google-books 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 375 次下载、GitHub Stars 达 1, 最近一次更新时间为 2022 年 10 月 01 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 angelleger/google-books 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 angelleger/google-books 我们能提供哪些服务?
定制开发 / 二次开发

基于 angelleger/google-books 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 16
  • 开发语言: PHP

其他信息

  • 授权协议: ISC
  • 更新时间: 2022-10-01