Download the PHP package merceslab/spreadsheet-client without Composer
On this page you can find all versions of the php package merceslab/spreadsheet-client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download merceslab/spreadsheet-client
More information about merceslab/spreadsheet-client
Files in merceslab/spreadsheet-client
Package spreadsheet-client
Short Description Client abstraction for interaction with Google online spreadsheets
License MIT
Informations about the package spreadsheet-client
Install
composer require merces-lab/spreadsheet-client
Usage
You'll need a Google Service Account to use the clients from this component. For reference, the Google documentation about the steps described below: https://developers.google.com/identity/protocols/OAuth2ServiceAccount#delegatingauthority
If you don't already have a service account you can use for your application:
- Go to the Google developer console: https://console.developers.google.com
- Create a project for your application (top left corner nex to the Google APIs logo)
- Select your project
- Go to "Enable API and services" (top of the screen) and enable the "Google Sheets API"
- Go to "Credentials" (left menu)
- In the "Create Credentials" dropdown menu, chose "Service account key"
- Choose a name for the service account.
- The service account does not need a role to be able to access Google Sheets.
- Select "JSON" as the "Key type"
- You will be prompted to download the credentials file. Save that file to your disk.
- Keep the Credentials page you should be redirected to open. You will need to copy the ID of the service account you just created in the next step.
Give the necessary authorization to your service account:
- Go to the admin console: http://admin.google.com/
- Go to Security > Advanced settings > Manage API client access
- Enter your service account ID as a Client Name and the https://www.googleapis.com/auth/spreadsheets API scope
- Click Authorize
You should now have a service account authorized to access the Google Sheets API. You will need to share the document you want to import data from or export data to with the service account you just created. To give your service account access to the document:
- Go to the Credentials page in the developer console
- Go to "Manage service accounts"
- Copy the email address of your service account
- Go to your Google Spreadsheet document
- Click "Share"
- In the "Invite people" field, enter the email address of your service account
- Uncheck "Notify people"
- Click "Send"
Google_Service_Sheets
To instantiate a \Google_Service_Sheets, you will need the credentials from the JSON file provided in the create service account steps. You can either have the file somewhere on your server file system, or have the content in an environment variable.
The \MercesLab\Component\SpreadsheetClient\ClientFactory helper class will create the Google Service for you. You will need to pass it the credentials, either as an array or as a JSON string.
The classes from this components depend on that \Google_Service_Sheets.
Client
The client only depends on the GoogleServiceSheets and implements a write() and read() methods. You should use the client if you need to access multiple google spreadsheet documents at once.
The read and write operation require the file ID, and an optional sheet name and range for the table
File
The file depends on the GoogleServiceSheets and the fileId. It also implements a write() and read() methods. You should use the file if you need to access the same spreadsheet document across multiple services.
The read and write operation require an optional sheet name and range for the table
Sheet
The sheet depends on the GoogleServiceSheets, the fileId, and an optional sheet name. It also implements a write() and read() methods. You should use the sheet if you need to access the same sheet from the same spreadsheet document across multiple services.
The read and write operation require an optional range for the table
File
The table depends on the GoogleServiceSheets, the fileId, and an optional sheet name and range. It also implements a write() and read() methods. You should use the file if you need to access the same table across multiple services.