PHP code example of ondram / simple-google-reader

1. Go to this page and download the library: Download ondram/simple-google-reader library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ondram / simple-google-reader example snippets


 declare(strict_types=1);

use Cache\Adapter\Filesystem\FilesystemCachePool;
use Cocur\Slugify\Slugify;
use League\Flysystem\Adapter\Local;
use League\Flysystem\Filesystem;
use OndraM\SimpleGoogleReader\Spreadsheets\SpreadsheetsReader;

->setAuthConfig(__DIR__ . '/data/google_client.json');
// If you service account has domain-wide delegation access, you need to use setSubject to set the name of the user
// which will the service account impersonate. This user also must have right to access the spreadsheet.
$client->setSubject('[email protected]');

// see below for spreadsheets and docs usage

// $client is the instance from above example

$client->addScope(\Google\Service\Sheets::SPREADSHEETS);

// Create instance of Slugify, needed for spreadsheets
$slugify = new Slugify(['rulesets' => ['default', 'czech']]);

$reader = new SpreadsheetsReader($client, $slugify, $cache);

$rows = $reader->readById('pasteHereGoogleSpreadsheedId', '[optional sheet name]'/*, optional cache TTL*/);
foreach ($rows as $row) {
    echo $row['first_column'];
    echo $row['second_column'];
}

[
    ['first_column' => 'Value 1', 'second_column' => 'Foo'],
    ['first_column' => 'Value 2', 'second_column' => 'Bar'],
]

// $client is the instance from above example

$client->addScope(\Google\Service\Docs::DOCUMENTS_READONLY);

$docsReader = new DocsReader($client, $cache);

$document = $docsReader->readAsPlaintext('pasteHereGoogleDocsId'/*, optional cache TTL*/);

$client->addScope(\Google\Service\Docs::DRIVE_READONLY);

$html = $docsReader->readAsHtml('pasteHereGoogleDocsId'/*, optional cache TTL*/);