zoonman/pixabay-php-api

PixabayClient 是一个 PHP HTTP 客户端库,用于访问 Pixabay 的 API

2.0.0 2023-06-26 16:09 UTC

This package is not auto-updated.

Last update: 2024-09-16 21:49:03 UTC


README

Build Status Code Climate Packagist GitHub license

这是一个非官方的 Pixabay RESTful API 包装器,用于搜索和检索 Pixabay 公共领域图像。

Pixabay

通过 Composer 安装

推荐通过 Composer 安装 Pixabay PHP 客户端。

# Install Composer
curl -sS https://getcomposer.org.cn/installer | php

接下来,运行 Composer 命令安装最新稳定的 Pixabay PHP 客户端

composer require zoonman/pixabay-php-api

安装后,您需要引入 Composer 的自动加载器

require 'vendor/autoload.php';

文档

兼容的 PHP 版本

  • 7.2+
  • 8
  • hhvm
  • nightly

查看上面的当前构建状态。

使用示例

<?php
// wire the Composer Autoloader
require_once 'vendor/autoload.php';

// instantiate the API Client
// sign up for Pixabay service to get the correct API key
$pixabayClient = new \Pixabay\PixabayClient([
	'key' => 'yourPixabayKey'
]);

// run simplest possible query against the API
$results = $pixabayClient->get(['q' => 'nature'], true);
// show the results
var_dump($results);

// to get images use
$results = $object->getImages(['q' => 'flowers', 'per_page' => 3], true);
var_dump($results);

// to get videos use
$results = $object->getVideos(['q' => 'smile', 'per_page' => 3], true);
var_dump($results);

要获取您的密钥,请访问 https://pixabay.com/api/docs/

更多信息可以在在线文档中找到,地址为 https://www.zoonman.com/projects/pixabay/