Esempio n. 1
0
<?php

require_once 'GWT_IndexStatus.php';
/**
 * Example 1
 * Get a JSON array containing Index-Status data
 * for a single domain that is registered in a GWT account.
 */
try {
    // Create a new class instance.
    $indx = new GWT_IndexStatus();
    $json = $indx->getDataByDomain('http://www.domain.tld/');
    # NOTE: Must have a trailing slash!
    // Remember: You can use the optional 2nd parameter for `json_decode()`
    // to get a native PHP array, instead of an stdClass-object.
    // @see: http://www.php.net/manual/en/function.json-decode.php
    print '<pre>';
    print_r(json_decode($json));
    print '</pre>';
} catch (Exception $e) {
    die($e->getMessage());
}
Esempio n. 2
0
<?php

require_once 'GWT_IndexStatus.php';
/**
 * Example 2
 * Get a JSON array containing Index-Status data for all domains
 * registered in a GWT account. But exclude a specific resultset.
 */
try {
    $indx = new GWT_IndexStatus();
    $indx->setParam('is-rbt', 0);
    # exclude 'blocked by robots.txt'-data
    $json = $indx->getDataAllDomains();
    print '<pre>';
    print_r(json_decode($json));
    print '</pre>';
} catch (Exception $e) {
    die($e->getMessage());
}
Esempio n. 3
0
<?php

require_once 'GWT_IndexStatus.php';
/**
 * Example 3
 * Get Index-Status data for all domains registered in a GWT account
 * and save resultsets to separated CSV files - one CSV file per domain.
 */
try {
    $indx = new GWT_IndexStatus();
    $json = $indx->getDataAllDomains();
    $domains = json_decode($json);
    foreach ($domains as $domain) {
        $data = $domain->indexData;
        $colCount = sizeof($data->cols);
        // Get column label names for CSV headline
        $labels = array();
        for ($i = 0; $i < $colCount; $i++) {
            $labels[] = $data->cols[$i]->label;
        }
        $cols = implode(';', $labels);
        // Start new CSV output string.
        $csv = "{$cols}\n";
        // Iterate through all resultsets and add rows to CSV output string
        // containing the columns as defined per instance.
        foreach ($data->rows as $r) {
            $row = array();
            for ($i = 0; $i < $colCount; $i++) {
                $row[] = $r->c[$i]->v;
            }
            $csv .= implode(';', $row) . "\n";