PHP code example of yangusik / shikimori-api-php

1. Go to this page and download the library: Download yangusik/shikimori-api-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

yangusik / shikimori-api-php example snippets




$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();
}



$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": { ...




$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());