Пример #1
0
define('AD_MAX_PAGE_SIZE', 50);
// This is the maximum number of obtainable rows for paged reports.
define('AD_ROW_LIMIT', 5000);
// Include the dependencies and die if any is not met.
try {
    require_once "AdSenseAuth.php";
    require_once "BaseExample.php";
    require_once "htmlHelper.php";
} catch (Exception $e) {
    die('Missing requirement: ' . $e->getMessage() . "\n");
}
try {
    // Build the list of supported actions.
    $actions = getSupportedActions();
    // Go through API authentication.
    $auth = new AdSenseAuth();
    $auth->authenticate('sample_user');
    // To get rid of the code in the URL after the authentication.
    if (isset($_GET['code'])) {
        header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);
    }
    // If the action is set dispatch the action if supported
    if (isset($_GET["action"])) {
        $action = $_GET["action"];
        if (!in_array($action, $actions)) {
            die('Unsupported action:' . $action . "\n");
        }
        // Render the required action.
        require_once 'examples/' . $action . '.php';
        $class = ucfirst($action);
        $example = new $class($auth->getAdSenseService());