"; error_reporting(E_ERROR); session_start(); require_once realpath(dirname(__FILE__) . '/../src/Google/autoload.php'); include_once 'testdodania.php'; $client = new Google_Client(); // Get your credentials from the console $client->setClientId('751962231483-1pnk4heu9rc6mc38lb8sjfc6lo2qfqcn.apps.googleusercontent.com'); $client->setClientSecret('C6vjyBug2W2h7JefuMnlO-4j'); $client->setRedirectUri('http://localhost:8090/test/examples/idtoken.php?module=Administration'); $client->setScopes(array('https://www.googleapis.com/auth/calendar','https://www.googleapis.com/auth/userinfo.email','https://www.googleapis.com/auth/userinfo.profile')); //Calender Scope $cal=new Google_Service_Calendar($client); $plus = new Google_Service_Oauth2($client); $authUrl = $client->createAuthUrl(); if($_GET['code']){ $accessToken = $client->authenticate($_GET['code']); $client->setAccessToken($accessToken); if ($client->getAccessToken()) { $token = $client->getAccessToken(); $authObj = json_decode($token); $_SESSION['access_token'] = $token; $_SESSION['access_token_is_ok']=1; $userinfo = $plus->userinfo; print_r($userinfo->get()); } else { $_SESSION['access_token_is_ok']=0; } } echo $_SESSION['access_token_is_ok']; function save_refresh_token($your_saved_refresh_token){ if($client->isAccessTokenExpired()){ $client->refreshToken($your_saved_refresh_token); $_SESSION['access_token'] = $client->getAccessToken(); } } var_dump($_SESSION['access_token']); if(is_array($_SESSION['access_token'])){ $authObj = json_decode($_SESSION['access_token']); if(isset($authObj->refresh_token)) { save_refresh_token($authObj->refresh_token); } } if($authUrl && $_SESSION['access_token_is_ok']==0){ echo "Kliknij aby sie zalogowac"; } else { addEvent($cal); } ?>