public function init() { $client = new \Imgur\Client(); $client->setOption('client_id', $this->pluginConfig['api']['id']); $client->setOption('client_secret', $this->pluginConfig['api']['secret']); if ($this->pluginConfig['session']['token']) { $client->setAccessToken($this->pluginConfig['api']['token']); if ($client->checkAccessTokenExpired()) { $client->refreshToken(); } else { \Util::console('Obtain new Imgur token and add it to config: ' . $client->getAuthenticationUrl()); } } $this->client = $client; }
<?php // This file is generated by Composer require_once 'vendor/autoload.php'; $client = new \Imgur\Client(); $client->setOption('client_id', '0910235d51f0f8e'); $client->setOption('client_secret', 'd8b71f04952f23b23a805f8f14a79cb6e7c92912'); 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 { } $images = $client->api('gallery')->randomGalleryImages(); $imageNumber = rand(0, 40); // If strength length of $images[$imageNumber]->getLink() is short, get a new image number $link = $images[$imageNumber]->getLink(); $title = $images[$imageNumber]->getTitle(); ?> <!DOCTYPE html> <html> <head> <title><?php echo $title; ?> </title> <meta charset="UTF-8">