yangusik / shikimori-api-php
A PHP wrapper for Shikimori API
v0.5.2
2022-08-17 14:02 UTC
Requires
- php: ^7.4 || ^8.0
- ext-curl: *
- ext-json: *
Requires (Dev)
- php-coveralls/php-coveralls: ^2.5
- phpunit/phpunit: ^9.5
- squizlabs/php_codesniffer: ^3.7
This package is auto-updated.
Last update: 2024-05-17 17:54:03 UTC
README
🔌 A PHP wrapper for the http://shikimori.one API
This is a PHP wrapper for Shikimori Web API. It includes the following:
- Helper methods for all API endpoints
- Authorization Code.
- Automatic refreshing of access tokens.
- Automatic retry of rate limited requests.
- PSR-4 autoloading support.
Requirements
- PHP 7.4 or later.
- PHP cURL extension (Usually included with PHP).
- PHP Json extension (Usually included with PHP).
Installation
Install it using Composer:
composer require yangusik/shikimori-api-php
Usage
Before using the Shikimori API, you'll need to create an app at Shikimori app.
Simple example displaying a user's profile:
require 'vendor/autoload.php'; $session = new ShikimoriAPI\Session( 'CLIENT_ID', 'CLIENT_SECRET', 'REDIRECT_URI' ); $api = new ShikimoriAPI\ShikimoriAPI(['auto_refresh' => false]); if (isset($_GET['code'])) { $session->requestAccessToken($_GET['code']); // use session to make auto-refresh token auto_refresh = true $api->setSession($session); // or just a token if you don't need auto-refresh token $api->setAccessToken($session->getAccessToken()); print_r($api->whoami()); } else { $options = [ 'scope' => [ 'user-read-email', ], ]; header('Location: ' . $session->getAuthorizeUrl($options)); die(); }
Some resources do not require a token, such as anime
require 'vendor/autoload.php'; $animes = new \ShikimoriAPI\Resources\Animes(); $animeList = $animes->getAll([['order' => 'popularity', 'status' => 'latest', 'limit' => 50]]); print_r($animeList); /** * [ * ["id" => 1069, * "name" => "Chou Denji Machine Voltes V", * "russian" => "Суперэлектромагнитная машина Вольтес V", * "image": { ...
All options for getAll can see at documentation Shikimori.
If the resource requires a token, such as Dialog
require 'vendor/autoload.php'; $api = new \ShikimoriAPI\ShikimoriAPI(); $api->setAccessToken('TOKEN'); $dialog = new \ShikimoriAPI\Resources\Dialogs($api); print_r($dialog->getAll()); // or $session = new ShikimoriAPI\Session( 'CLIENT_ID', 'CLIENT_SECRET', 'REDIRECT_URI' ); $session->setAccessToken('TOKEN'); $session->setRefreshToken('TOKEN'); $api = new ShikimoriAPI\ShikimoriAPI(['auto_refresh' => true]); $api->setSession($session); $dialog = new \ShikimoriAPI\Resources\Dialogs($api); print_r($dialog->getAll());
For more instructions and examples, check out the documentation. (soon)
License
MIT license. Please see LICENSE for more info.