Download the PHP package ondram/simple-google-reader without Composer
On this page you can find all versions of the php package ondram/simple-google-reader. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ondram/simple-google-reader
More information about ondram/simple-google-reader
Files in ondram/simple-google-reader
Package simple-google-reader
Short Description Super simple Google Spreadsheets and Google Docs reader
License MIT
Informations about the package simple-google-reader
Simple Google Spreadsheets and Docs Reader
PHP library providing a simple way to load data from Google Spreadsheets and Google Docs.
The aim is to provide universal low-level access to the data, without any additional features like data manipulation or formatting. It means you can implement any domain object mapping or data processing in your application.
This library is a wrapper for google/apiclient, with minimal additional dependency footprint. It is intended to be easily integrated to any framework or pure PHP.
Installation
Install using Composer:
Usage
- Obtain service account credentials for your project
- 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
). - 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.
- Enable required APIs in Google Cloud Console for your project:
- Google Sheets API if you plan reading Spreadsheets
- Google Docs API to read Docs
- Google Drive API if you need to read Docs as HTML
- 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)
- Make sure to install any package implementing PSR-6 caching
- Prepare cache and initialize Google Client:
Reading spreadsheets
In Google Cloud Console, do not forget to enable Google Sheets API.
For spreadsheets, it is required that the first row contains column names. The library will use these names (converted to slugs) as keys in the associative array. Consider table:
First column | Second column |
---|---|
Value 1 | Foo |
Value 2 | Bar |
This will be read as:
Empty rows are skipped. There is currently (intentional) limitation to read columns A:Z only.
Reading documents
As plaintext
In Google Cloud Console, do not forget to enable Google Docs API.
This will read the whole document as plain text. Only text elements are included, other elements like tables are ignored. Also, any document formatting is ignored.
As HTML
To read document as HTML, do not forget to enable Google Drive API in Google Cloud console.
Note the output will be quite bloated-HTML, with many inline styles and nested elements. It may be useful to apply on the output some HTML sanitizer like symfony/html-sanitizer to remove unwanted elements and attributes.
Testing
Tests in this library are mainly integration, meaning they require real Google API access.
To run them, you must download and store JSON credentials for you service account to tests/google_client.json
file.
The tests then use this table and this document to read example data.
Changelog
For latest changes see Semantic Versioning.
All versions of simple-google-reader with dependencies
cocur/slugify Version ^4.3
google/apiclient Version ^2.13
psr/simple-cache Version ^1.0
psr/simple-cache-implementation Version ^1.0 || ^2.0 || ^3.0