cetteup/unsplash

访问Unsplash API的非官方PHP包装器

v1.1 2020-06-27 09:25 UTC

This package is not auto-updated.

Last update: 2024-09-16 03:38:26 UTC


README

这是一个非官方的PHP包装器,用于访问Unsplash API,专注于API调用效率和易用性。

注意: 此包装器仅支持公开操作

安装

Unsplash-PHP 使用 Composer。要使用它,请要求库

composer require cetteup/unsplash

使用方法

配置

在您可以开始调用API之前,您需要使用您的应用程序ID配置客户端。

$unsplash = new Cetteup\Unsplash\HttpClient('YOUR APPLICATION ID');

API方法

有关响应结构的更详细信息,请参阅官方文档

Cetteup\Unsplash\HttpClient->user_find($username)

检索特定用户的公开详细信息。

注意: 您需要首先实例化一个httpclient对象

参数

示例

$unsplash = new Cetteup\Unsplash\HttpClient('YOUR APPLICATION ID');
$user = $unsplash->user_find('cetteup');

Cetteup\Unsplash\HttpClient->user_portfolio_link($username)

检索单个用户的个人作品链接。

注意: 您需要首先实例化一个httpclient对象

参数

示例

$unsplash = new Cetteup\Unsplash\HttpClient('YOUR APPLICATION ID');
$link = $unsplash->user_portfolio_link('cetteup');

Cetteup\Unsplash\HttpClient->user_photos($username, $page, $per_page, $order_by, $stats, $resolution, $quantity, $orientation)

获取用户上传的相片列表。

注意: 您需要首先实例化一个httpclient对象

参数

示例

$unsplash = new Cetteup\Unsplash\HttpClient('YOUR APPLICATION ID');
$photos = $unsplash->user_photos('cetteup', 2, 30, 'oldest');

Cetteup\Unsplash\HttpClient->user_likes($username, $page, $per_page, $order_by, $orientation)

获取用户喜欢的相片列表。

注意: 您需要首先实例化一个httpclient对象

参数

示例

$unsplash = new Cetteup\Unsplash\HttpClient('YOUR APPLICATION ID');
$photos = $unsplash->user_likes('cetteup', 2, 20, 'popular');

Cetteup\Unsplash\HttpClient->user_collections($username, $page, $per_page)

获取用户创建的收藏夹列表。

注意: 您需要首先实例化一个httpclient对象

参数

示例

$unsplash = new Cetteup\Unsplash\HttpClient('YOUR APPLICATION ID');
$collections = $unsplash->user_collections('jlantunez', 3, 5);

Cetteup\Unsplash\HttpClient->user_statistics($username, $resolution, $quantity)

检索用户所有相片的下载次数、浏览次数和点赞次数的汇总数据,以及这些统计数据的历史分解和特定时间段内的平均值。

注意: 您需要首先实例化一个httpclient对象

参数

示例

$unsplash = new Cetteup\Unsplash\HttpClient('YOUR APPLICATION ID');
$collections = $unsplash->user_statistics('cetteup', 'days', 10);

Cetteup\Unsplash\HttpClient->photo_all($page, $per_page, $order_by)

获取所有相片列表的单页。

注意: 您需要首先实例化一个httpclient对象

参数

示例

$unsplash = new Cetteup\Unsplash\HttpClient('YOUR APPLICATION ID');
$photos = $unsplash->photo_all(2, 30, 'oldest');

Cetteup\Unsplash\HttpClient->photo_find($id)

检索单个相片。

注意: 您需要首先实例化一个httpclient对象

参数

示例

$unsplash = new Cetteup\Unsplash\HttpClient('YOUR APPLICATION ID');
$photo = $unsplash->photo_find('54t5rivyAiI');

Cetteup\Unsplash\HttpClient->photo_random($params)

根据可选过滤器检索单个随机相片。

注意: 您需要首先实例化一个httpclient对象

参数

示例

$unsplash = new Cetteup\Unsplash\HttpClient('YOUR APPLICATION ID');
$photo = $unsplash->photo_random(['orientation' => 'portrait']);

Cetteup\Unsplash\HttpClient->photo_statistics($id, $resolution, $quantity)

检索单个相片的下载次数、浏览次数和点赞次数的汇总数据,以及这些统计数据在特定时间段内的历史分解。

注意: 您需要首先实例化一个httpclient对象

参数

示例

$unsplash = new Cetteup\Unsplash\HttpClient('YOUR APPLICATION ID');
$stats = $unsplash->photo_statistics('54t5rivyAiI', 'days', 14);

Cetteup\Unsplash\HttpClient->photo_download($id)

跟踪相片下载。

注意: 您需要首先实例化一个httpclient对象

参数

示例

$unsplash = new Cetteup\Unsplash\HttpClient('YOUR APPLICATION ID');
$unsplash->photo_download('54t5rivyAiI');

Cetteup\Unsplash\HttpClient->search_photos($search, $page, $per_page, $order_by, $content_filter, $collections, $color, $orientation)

为查询获取相片结果的单页。

注意: 您需要首先实例化一个httpclient对象

参数

示例

$unsplash = new Cetteup\Unsplash\HttpClient('YOUR APPLICATION ID');
$results = $unsplash->search_photos('cats', 5, 30);

Cetteup\Unsplash\HttpClient->search_collections($search, $page, $per_page)

为查询获取收藏夹结果的单页。

注意: 您需要首先实例化一个httpclient对象

参数

示例

$unsplash = new Cetteup\Unsplash\HttpClient('YOUR APPLICATION ID');
$results = $unsplash->search_collections('dogs', 10, 25);

Cetteup\Unsplash\HttpClient->search_users($search, $page, $per_page)

为查询获取用户结果的单页。

注意: 您需要首先实例化一个httpclient对象

参数

示例

$unsplash = new Cetteup\Unsplash\HttpClient('YOUR APPLICATION ID');
$results = $unsplash->search_users('photography', 1, 15);

Cetteup\Unsplash\HttpClient->collection_all($page, $per_page)

获取所有收藏夹列表的单页。

注意: 您需要首先实例化一个httpclient对象

参数

示例

$unsplash = new Cetteup\Unsplash\HttpClient('YOUR APPLICATION ID');
$collections = $unsplash->collection_all(10, 30);

Cetteup\Unsplash\HttpClient->collection_featured($page, $per_page)

获取特色收藏夹列表的单页。

注意: 您需要首先实例化一个httpclient对象

参数

示例

$unsplash = new Cetteup\Unsplash\HttpClient('YOUR APPLICATION ID');
$collections = $unsplash->collection_featured(2, 10);

Cetteup\Unsplash\HttpClient->collection_find($id)

检索单个收藏夹。

注意: 您需要首先实例化一个httpclient对象

参数

示例

$unsplash = new Cetteup\Unsplash\HttpClient('YOUR APPLICATION ID');
$collection = $unsplash->collection_find(1121542);

Cetteup\Unsplash\HttpClient->collection_photos($id, $page, $per_page, $orientation)

检索收藏夹的相片。

注意: 您需要首先实例化一个httpclient对象

参数

示例

$unsplash = new Cetteup\Unsplash\HttpClient('YOUR APPLICATION ID');
$photos = $unsplash->collection_photos(1121542, 1, 10, 'squarish');

Cetteup\Unsplash\HttpClient->collection_related($id)

检索相关收藏夹列表。

注意: 您需要首先实例化一个httpclient对象

参数

示例

$unsplash = new Cetteup\Unsplash\HttpClient('YOUR APPLICATION ID');
$collections = $unsplash->collection_related(1121542);

Cetteup\Unsplash\HttpClient->stats_total()

获取所有Unsplash的统计数据列表。

注意: 您需要首先实例化一个httpclient对象

示例

$unsplash = new Cetteup\Unsplash\HttpClient('YOUR APPLICATION ID');
$stats = $unsplash->stats_total();

Cetteup\Unsplash\HttpClient->stats_month()

获取过去30天的整体Unsplash统计数据。

注意: 您需要首先实例化一个httpclient对象

示例

$unsplash = new Cetteup\Unsplash\HttpClient('YOUR APPLICATION ID');
$stats = $unsplash->stats_month();