コード例 #1
0
// 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">
  <meta name="description" content="Random images pulled from the Imgur API">
  <meta name="keywords" content="Funny, image, random, randomized">