meriksk / fotkomotko-php-sdk

该包的最新版本(0.1)没有可用的许可证信息。

Fotkomotko PHP SDK

0.1 2014-08-26 16:41 UTC

This package is auto-updated.

Last update: 2024-09-27 02:19:29 UTC


README

Fotkomotko 客户端是一个 SDK 库,允许从 Fotkomotko 服务获取数据。

基本用法

使用 new \Fotkomotko\Api($options) 创建并初始化一个 API 客户端。必须提供 base_url 选项。您至少需要以下内容

<?php
// require the Fotkomotko autoloader
require_once '/path/to/FotkomotkoClient/src/autoload.php';
// alternatively, use composer

$options = array(
	'base_url' => 'http://url-to-fotkomotko/api',
	'username' => 'your_username',
	'password' => 'your_password',
);
$api = new \Fotkomotko\Api($options);

使用 Composer

"meriksk/fotkomotko-php-sdk": "@stable" 添加到 composer.json 文件的 require 部分。运行 composer install。示例如下

require_once __DIR__ . '/vendor/autoload.php';

$options = [
	'base_url' => 'http://url-to-fotkomotko/api',
	'username' => 'your_username',
	'password' => 'your_password',
];

$api = new \Fotkomotko\Api($options);

端点

相册

// Get a single album (find by Id)
$response = $api->getAlbum(1);

	if ($response->success) {
		echo '<p>Album: <strong>' . $response->data['title'] . '</strong></p>';
	} else {
		echo '<p>Error: <strong>' . $response->code . ': ' . $response->message . '</strong></p>';
	}

// Get a single album (find by album title)
$response = $api->getAlbum('album-title');

	if ($response->success) {
		echo '<p>Album: <strong>' . $response->data['title'] . '</strong></p>';
	} else {
		echo '<p>Error: <strong>' . $response->code . ': ' . $response->message . '</strong></p>';
	}

// Get list of albums
$response = $api
	->visibility(\Fotkomotko\Api::VISIBILITY_PUBLIC)
	->continents(\Fotkomotko\Api::EUROPE)
	->years(2014)
	->sort('-date')
	->getAlbums(array(
		'tags' => 'europe'
	));

	if ($response->success) {
		foreach($response->data['items'] as $album { ... }
	} else {
		echo '<p>Error: <strong>' . $response->code . ': ' . $response->message . '</strong></p>';
	}

照片

// Get single photo
$response = $api->getPhoto(1);

	if ($response->success) {
		echo '<p>Photo: <strong>' . $response->data['title'] . '</strong></p>';
	} else {
		echo '<p>Error: <strong>' . $response->code . ': ' . $response->message . '</strong></p>';
	}

// Get list of photos from a single album
$response = $api->albums(1)->getAlbums($params);

	if ($response->success) {
		foreach($response->data['items'] as $photo { ... }
	} else {
		echo '<p>Error: <strong>' . $response->code . ': ' . $response->message . '</strong></p>';
	}

收藏夹

// Get single collection
$response = $api->getCollection(1);

	if ($response->success) {
		echo '<p>Collection: <strong>' . $response->data['title'] . '</strong></p>';
	} else {
		echo '<p>Error: <strong>' . $response->code . ': ' . $response->message . '</strong></p>';
	}

// Get list of collection
$response = $api->getCollections(array(
	'albums' => true,
	'coverPhoto' => true,
));

	if ($response->success) {
		foreach($response->data['items'] as $collection { ... }
	} else {
		echo '<p>Error: <strong>' . $response->code . ': ' . $response->message . '</strong></p>';
	}