'; print_r($_SERVER); echo ''; exit; $client = new Google_Client(); $client->setAuthConfigFile('client_secrets.json'); $client->addScope(Google_Service_Analytics::ANALYTICS_READONLY); $client->setAccessType('offline'); $accessToken = file_exists($config['tokenFile']) ? file_get_contents($config['tokenFile']) : false; $action = empty($_GET['action']) ? 'index' : $_GET['action']; if ($accessToken) { $client->setAccessToken($accessToken); } set_exception_handler(function (Exception $e) { echo '
'; echo $e->getTraceAsString(); echo ''; }); switch ($action) { case 'index': if (!$accessToken) { header('Location: ' . filter_var($config['redirectUri'], FILTER_SANITIZE_URL)); exit; } break; case 'authorize': $client->setRedirectUri($config['redirectUri']); if (!isset($_GET['code'])) { $authUrl = $client->createAuthUrl(); header('Location: ' . filter_var($authUrl, FILTER_SANITIZE_URL)); exit; } else { $client->authenticate($_GET['code']); file_put_contents($config['tokenFile'], $client->getAccessToken()); header('Location: ' . filter_var($config['baseUri'], FILTER_SANITIZE_URL)); exit; } break; default: break; } if ($client->isAccessTokenExpired()) { //echo 'Token is expired ' . $client->getAccessToken() . '
'; print_r($result->getRows()); echo ''; exit;