<?php
require_once('./google-api-php-client/src/Google/autoload.php');
session_start();
$client = new Google_Client();
$client->setClientId('クライアントID');
$client->setClientSecret('クライアントシークレット');
$client->setRedirectUri('リダイレクトURI');
if(isset($_GET['code'])){
$client->authenticate($_GET['code']);
$_SESSION['token'] = $client->getAccessToken();
header('Location: http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']);
exit;
}
if(isset($_SESSION['token'])){
$client->setAccessToken($_SESSION['token']);
}
if($client->getAccessToken()){
try {
echo "Google Drive Api 連携完了!<br>";
$_SESSION['client'] = $client;
} catch (Google_Exception $e){
echo $e->getMessage();
}
} else {
$client->setScopes(Google_Service_Drive::DRIVE);
$authUrl = $client->createAuthUrl();
echo '<a href="'.$authUrl.'">アプリケーションのアクセスを許可してください。</a>';
exit;
}
?>
<a href="list.php">ファイル一覧</a><br>
<a href="imageview.php">画像表示</a><br>
<a href="upload.php">アップロード</a>