shutterstock / api
1.0.0
2016-03-04 17:47 UTC
Requires
- php: >=5.6
- guzzlehttp/guzzle: ^6.1
- psr/log: ^1.0
Requires (Dev)
- codeclimate/php-test-reporter: dev-master
- phpunit/phpunit: ^5.0
This package is not auto-updated.
Last update: 2024-09-20 19:09:22 UTC
README
使用 Guzzle 与 Shutterstock API 交互的 PHP 客户端。
安装
使用 Composer 安装依赖项。
$ composer require shutterstock/api
使用方法
实例化客户端需要传递客户端 ID 和密钥,您可以在 Shutterstock 开发者网站 上注册。
<?php require_once __DIR__ . '/vendor/autoload.php'; $client = new Shutterstock\Api\Client($clientId, $clientSecret);
与不同端点交互就像阅读 API 文档 一样简单。客户端有两个主要方法来处理 - Client::get
和 Client::post
- 它们将端点作为第一个参数,客户端参数作为第二个参数。
// perform an image search for puppies $client->get('images/search', array('query' => 'puppies')); // retrieve details for a handful of image ids $client->get('images', array('id' => array(1, 2, 3))); // create a lightbox $client->post('images/collections', array('name' => 'Lightbox Name Here'));
每个请求将返回一个 PSR-7 响应对象,您可以在 Guzzle/PSR7 仓库 中了解更多信息。响应对象体已经装饰了 JsonSerializable 接口,以便更容易处理默认 API 响应。
$imageResponse = $client->get('images', array('id' => array(1, 2, 3))); if ($imageResponse->getStatusCode() != 200) { // error handler } $images = $imageResponse->getBody()->jsonSerialize()['data']; // etc
如果您的应用程序已配置为处理异步 CURL 请求,您还可以进行 Client::getAsync
和 Client::postAsync
调用,这些调用返回 Guzzle Promises。
有关更多示例和演示应用程序,请参阅 [链接在此处]。
许可
Apache 2.0 © 2016-2017 Shutterstock Images, LLC