承接 yangusik/shikimori-api-php 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

yangusik/shikimori-api-php

最新稳定版本:v0.5.2

Composer 安装命令:

composer require yangusik/shikimori-api-php

包简介

A PHP wrapper for Shikimori API

关键字:

README 文档

README

🔌 A PHP wrapper for the http://shikimori.one API

Packagist build Coverage Status

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

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.

统计信息

  • 总下载量: 4
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-08-11

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固