Пример #1
0
$client = new Google_Client();
$client->setClientId(CLIENT_ID);
$client->setClientSecret(CLIENT_SECRET);
$client->setRedirectUri(REDIRECT_URL);
$client->setApplicationName(APP_NAME);
$client->setScopes(array(ANALYTICS_SCOPE));
// Magic. Returns objects from the Analytics Service
// instead of associative arrays.
$client->setUseObjects(true);
// Build a new storage object to handle and store tokens in sessions.
// Create a new storage object to persist the tokens across sessions.
$storage = new apiSessionStorage();
$authHelper = new AuthHelper($client, $storage, THIS_PAGE);
// Main controller logic.
if ($_GET['action'] == 'revoke') {
    $authHelper->revokeToken();
} else {
    if ($_GET['action'] == 'auth' || $_GET['code']) {
        $authHelper->authenticate();
    } else {
        $authHelper->setTokenFromStorage();
        if ($authHelper->isAuthorized()) {
            $analytics = new Google_AnalyticsService($client);
            if ($_GET['demo'] == 'hello') {
                // Hello Analytics API Demo.
                require_once 'helloAnalyticsApi.php';
                $demo = new HelloAnalyticsApi($analytics);
                $htmlOutput = $demo->getHtmlOutput();
                $demoError = $demo->getError();
            } else {
                if ($_GET['demo'] == 'mgmt') {