PHP code example of j0k3r / php-imgur-api-client

1. Go to this page and download the library: Download j0k3r/php-imgur-api-client 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/ */

    

j0k3r / php-imgur-api-client example snippets


// This file is generated by Composer
nt->setOption('client_id', '[your app client id]');
$client->setOption('client_secret', '[your app client secret]');

if (isset($_SESSION['token'])) {
    $client->setAccessToken($_SESSION['token']);

    if ($client->checkAccessTokenExpired()) {
        $client->refreshToken();
    }
} elseif (isset($_GET['code'])) {
    $client->requestAccessToken($_GET['code']);
    $_SESSION['token'] = $client->getAccessToken();
} else {
    echo '<a href="'.$client->getAuthenticationUrl().'">Click to authorize</a>';
}

$memes = $client->api('memegen')->defaultMemes();

$client->api('album');
$client->api('comment');
$client->api('customGallery');
// etc ...

// for "Account Base" in account
$client->api('account')->base();
// for "Account Gallery Profile" in account
$client->api('account')->accountGalleryProfile();

// for "Filtered Out Gallery" in Custom Gallery
$client->api('customGallery')->filtered();

// for "Random Gallery Images" in gallery
$client->api('gallery')->randomGalleryImages();

// etc ...

$pathToFile = '../path/to/file.jpg';
$imageData = [
    'image' => $pathToFile,
    'type'  => 'file',
];

$client->api('image')->upload($imageData);

$urlToFile = 'http://0.0.0.0/path/to/file.jpg';
$imageData = [
    'image' => $urlToFile,
    'type'  => 'url',
];

$client->api('image')->upload($imageData);

$pathToFile = '../path/to/file.jpg';
$imageData = [
    'image' => base64_encode(file_get_contents($pathToFile)),
    'type'  => 'base64',
];

$client->api('image')->upload($imageData);

$pager = new \Imgur\Pager\BasicPager(1, 10);
$images = $client->api('account', $pager)->images();

$page = 1;
$pager = new \Imgur\Pager\BasicPager();
$res = $client->api('account', $pager)->images();

while (!empty($res)) {
    // var_dump(count($res));

    $pager->setPage($page++);

    $res = $client->api('account', $pager)->images();
}

$data = $client->api('albumOrImage')->find($id);
bash
composer 
bash
$ php composer.phar install