PHP code example of jacklul / e621-api

1. Go to this page and download the library: Download jacklul/e621-api 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/ */

    

jacklul / e621-api example snippets


     
    use jacklul\E621API\E621;
    
    $api = new E621();

    $options = [
        'headers'  => [
            'User-Agent' => 'My project',
        ],
    ];
    
    $api = new E621($options);

    $request = $api->postIndex(['tags' => 'cat order:score', 'limit' => 25]);

    if ($request->isSuccessful()) {
        $results = $request->getResult();    // Result data (usually array of objects, empty array means no results)
    } else {
        echo $request->getReason();     // Failure reason
        echo $request->getMessage();    // Failure descriptive message (when available)
        echo $request->getRawResult();  // Raw response (when available)
    }

    /** @var \jacklul\E621API\Entity\Post $post */
    foreach ($results as $post) {
        echo $post->getFileUrl() . PHP_EOL;
    }

    $request = $api->postIndex(['tags' => 'cat order:score'], ['timeout' => 10]);

    $api->throwExceptions(false);   // Not recommended

    $api = new E621();
    $api->login('login', 'api_key');  // Set authentication data
    $request = $api->dmailInbox();
    $api->logout();                   // Remove authentication data

    $api->setProgressHandler([$this, 'progress']);
    $api->setProgressHandler(null);     // Unset the handler

    $api->setDebugLogHandler([$this, 'logger']);
    $api->setDebugLogHandler(null);     // Unset the handler