{"id":16057884,"url":"https://github.com/ondram/simple-google-reader","last_synced_at":"2025-09-06T19:38:26.400Z","repository":{"id":142916391,"uuid":"614397067","full_name":"OndraM/simple-google-reader","owner":"OndraM","description":"Super simple Google Spreadsheets and Google Docs reader for PHP","archived":false,"fork":false,"pushed_at":"2025-08-12T12:20:56.000Z","size":39,"stargazers_count":2,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-08-30T17:52:47.112Z","etag":null,"topics":["google-api","google-docs","google-spreadsheet","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/OndraM.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-03-15T14:01:45.000Z","updated_at":"2024-12-23T11:17:51.000Z","dependencies_parsed_at":"2024-01-29T10:48:12.928Z","dependency_job_id":"e03c4398-53b0-4fa2-9c54-9dbb9f21dda9","html_url":"https://github.com/OndraM/simple-google-reader","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/OndraM/simple-google-reader","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OndraM%2Fsimple-google-reader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OndraM%2Fsimple-google-reader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OndraM%2Fsimple-google-reader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OndraM%2Fsimple-google-reader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/OndraM","download_url":"https://codeload.github.com/OndraM/simple-google-reader/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OndraM%2Fsimple-google-reader/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273954886,"owners_count":25197575,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-06T02:00:13.247Z","response_time":2576,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["google-api","google-docs","google-spreadsheet","php"],"created_at":"2024-10-09T03:05:14.814Z","updated_at":"2025-09-06T19:38:26.361Z","avatar_url":"https://github.com/OndraM.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Simple Google Spreadsheets and Docs Reader\n\n[![Latest Stable Version](https://img.shields.io/packagist/v/ondram/simple-google-reader.svg?style=flat-square)](https://packagist.org/packages/ondram/simple-google-reader)\n[![Coverage Status](https://img.shields.io/coveralls/OndraM/simple-google-reader/main.svg?style=flat-square)](https://coveralls.io/r/OndraM/simple-google-reader)\n[![GitHub Actions Build Status](https://img.shields.io/github/actions/workflow/status/OndraM/simple-google-reader/tests.yaml?style=flat-square\u0026label=GitHub%20Actions%20build)](https://github.com/OndraM/simple-google-reader/actions)\n\nPHP library providing a simple way to load data from Google Spreadsheets and Google Docs.\n\nThe aim is to provide universal low-level access to the data, without any additional features like data manipulation\nor formatting. It means you can implement any domain object mapping or data processing in your application.\n\nThis library is a wrapper for [google/apiclient](https://github.com/googleapis/google-api-php-client),\nwith minimal additional dependency footprint. It is intended to be easily integrated to any framework or pure PHP.\n\n## Installation\n\nInstall using [Composer](https://getcomposer.org/):\n\n```sh\n$ composer require ondram/simple-google-reader\n```\n\n## Usage\n\n1. [Obtain service account credentials](https://github.com/googleapis/google-api-php-client#authentication-with-service-accounts) for your project\n1. In service account details in IAM admin console open Keys settings and add JSON keys. Download generated JSON file with credentials (save for example as `google_client.json`).\n1. Optional: You can setup domain-wide delegation access for the service account. This is done in Google Workspace Admin. In that case the service account can impersonate any domain user.\n1. Enable required APIs in [Google Cloud Console](https://console.cloud.google.com/apis/dashboard) for your project:\n   - [Google Sheets API](https://console.cloud.google.com/apis/library/sheets.googleapis.com) if you plan reading Spreadsheets\n   - [Google Docs API](https://console.cloud.google.com/apis/library/docs.googleapis.com) to read Docs\n   - [Google Drive API](https://console.cloud.google.com/apis/library/drive.googleapis.com) if you need to read Docs as HTML\n1. Share the intended document with your service account (or if you use domain-wide delegation, then with some user account), copy document ID (from the URL)\n1. Make sure to install any package [implementing PSR-6 caching](https://packagist.org/providers/psr/simple-cache-implementation)\n1. Prepare cache and initialize Google Client:\n\n```php\n\u003c?php declare(strict_types=1);\n\nuse Cache\\Adapter\\Filesystem\\FilesystemCachePool;\nuse Cocur\\Slugify\\Slugify;\nuse League\\Flysystem\\Adapter\\Local;\nuse League\\Flysystem\\Filesystem;\nuse OndraM\\SimpleGoogleReader\\Spreadsheets\\SpreadsheetsReader;\n\nrequire_once __DIR__ . '/vendor/autoload.php';\n\n// Create instance of Cache, in this case we use FilesystemCache\n$cache = new FilesystemCachePool(new Filesystem(new Local(__DIR__ . '/data')));\n\n// Instantiate the Google Client with your credentials\n$client = new \\Google\\Client();\n$client-\u003esetAuthConfig(__DIR__ . '/data/google_client.json');\n// If you service account has domain-wide delegation access, you need to use setSubject to set the name of the user\n// which will the service account impersonate. This user also must have right to access the spreadsheet.\n$client-\u003esetSubject('foo@bar.cz');\n\n// see below for spreadsheets and docs usage\n```\n\n### Reading spreadsheets\n\nIn Google Cloud Console, do not forget to enable [Google Sheets API](https://console.cloud.google.com/apis/library/sheets.googleapis.com).\n\n```php\n// $client is the instance from above example\n\n$client-\u003eaddScope(\\Google\\Service\\Sheets::SPREADSHEETS);\n\n// Create instance of Slugify, needed for spreadsheets\n$slugify = new Slugify(['rulesets' =\u003e ['default', 'czech']]);\n\n$reader = new SpreadsheetsReader($client, $slugify, $cache);\n\n$rows = $reader-\u003ereadById('pasteHereGoogleSpreadsheedId', '[optional sheet name]'/*, optional cache TTL*/);\nforeach ($rows as $row) {\n    echo $row['first_column'];\n    echo $row['second_column'];\n}\n```\n\nFor spreadsheets, it is required that the first row contains column names. The library will use these names (converted to slugs)\nas keys in the associative array. Consider table:\n\n| First column | Second column |\n|--------------|---------------|\n| Value 1      | Foo           |\n| Value 2      | Bar           |\n\nThis will be read as:\n\n```php\n[\n    ['first_column' =\u003e 'Value 1', 'second_column' =\u003e 'Foo'],\n    ['first_column' =\u003e 'Value 2', 'second_column' =\u003e 'Bar'],\n]\n```\n\nEmpty rows are skipped. There is currently (intentional) limitation to read columns A:Z only.\n\n### Reading documents\n\n#### As plaintext\n\nIn Google Cloud Console, do not forget to enable [Google Docs API](https://console.cloud.google.com/apis/library/docs.googleapis.com).\n\n```php\n// $client is the instance from above example\n\n$client-\u003eaddScope(\\Google\\Service\\Docs::DOCUMENTS_READONLY);\n\n$docsReader = new DocsReader($client, $cache);\n\n$document = $docsReader-\u003ereadAsPlaintext('pasteHereGoogleDocsId'/*, optional cache TTL*/);\n```\n\nThis will read the whole document as plain text. Only text elements are included, other elements like tables are\nignored. Also, any document formatting is ignored.\n\n#### As HTML\n\nTo read document as HTML, do not forget to enable [Google Drive API](https://console.cloud.google.com/apis/library/drive.googleapis.com) in Google Cloud console.\n\n```php\n$client-\u003eaddScope(\\Google\\Service\\Docs::DRIVE_READONLY);\n\n$html = $docsReader-\u003ereadAsHtml('pasteHereGoogleDocsId'/*, optional cache TTL*/);\n```\n\nNote the output will be quite bloated-HTML, with many inline styles and nested elements. It may be useful to apply\non the output some HTML sanitizer like [symfony/html-sanitizer](https://symfony.com/doc/current/html_sanitizer.html)\nto remove unwanted elements and attributes.\n\n## Testing\n\nTests in this library are mainly integration, meaning they require real Google API access.\nTo run them, you must download and store JSON credentials for you service account to `tests/google_client.json` file.\n\nThe tests then use [this table](https://docs.google.com/spreadsheets/d/1cEgUJA35YE56jn3JQRrJMfXKK9rkw0qaWEiYWnADLa8/edit)\nand [this document](https://docs.google.com/document/d/1T46U8sJEimVDhtmixxKLtf7Oxl1FzM2ae2EDYQ-HT_4/edit)\nto read example data.\n\n```sh\n$ composer test\n```\n\n## Changelog\nFor latest changes see [CHANGELOG.md](CHANGELOG.md) file. This project follows [Semantic Versioning](https://semver.org/).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fondram%2Fsimple-google-reader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fondram%2Fsimple-google-reader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fondram%2Fsimple-google-reader/lists"}