처음 로그인 할 때 제대로 작동하는이 코드가 있지만 페이지가 열린 상태에서 세션을 로그 아웃하지 않으면 다음 메시지가 표시되고 브라우저를 다시 시작해야합니다 내 페이지를 다시 올리려고. 토큰을 자동으로 새로 고칠 수 있습니까?Google OAuth Token Expires
Fatal error: Uncaught exception 'Google_Auth_Exception' with message 'The OAuth 2.0 access token has expired, and a refresh token is not available. Refresh tokens are not returned for responses that were auto-approved.'...
이 코드
<?php
require_once __DIR__.'/gplus-lib/vendor/autoload.php';
const CLIENT_ID = 'CLIENT_ID';
const CLIENT_SECRET = 'CLIENT_SECRET';
const REDIRECT_URI = 'REDIRECT_URI';
session_start();
$client = new Google_Client();
$client->setClientId(CLIENT_ID);
$client->setClientSecret(CLIENT_SECRET);
$client->setRedirectUri(REDIRECT_URI);
$client->setScopes('email');
$plus = new Google_Service_Plus($client);
if (isset($_REQUEST['logout'])) {
session_unset();
}
if (isset($_GET['code'])) {
$client->authenticate($_GET['code']);
$_SESSION['access_token'] = $client->getAccessToken();
$redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
}
if (isset($_SESSION['access_token']) && $_SESSION['access_token']) {
$client->setAccessToken($_SESSION['access_token']);
$me = $plus->people->get('me');
// Get User data
$id = $me['id'];
$name = $me['displayName'];
$email = $me['emails'][0]['value'];
$profile_image_url = $me['image']['url'];
} else {
// get the login url
$authUrl = $client->createAuthUrl();
}
?>
<div>
if (isset($authUrl)) {
echo "<a class='login' href='" . $authUrl . "'><img src='gplus-lib/signin_button.png' height='50px'/></a>";
} else { ?>
<!-- Some HTML -->
<?php
}
?>
</div>