silinternational / google-sheets-php
A simple library for pushing data to a Google Sheet using the Google PHP API Client version 1
Installs: 7 517
Dependents: 0
Suggesters: 0
Security: 0
Stars: 10
Watchers: 6
Forks: 2
Open Issues: 0
Requires
- php: ^7.4||^8.1
- ext-json: *
- google/apiclient: ^v1.1.9
- google/apiclient-services: ^0.176
Requires (Dev)
- behat/behat: ^3.6
- roave/security-advisories: dev-master
- silinternational/php-env: ^2.1||^3.0
This package is auto-updated.
Last update: 2024-10-30 01:42:52 UTC
README
A simple library for pushing data to a Google Sheet using the Google PHP API Client version 1.
Authorization
To use this library to push data to a Google Sheet...
- Go to the Google Developers Console.
- If you do not yet have a project that you plan to use this with, create one.
- Enable the "Google Sheets API" for that project.
- Create credentials for the project:
- To use the Google Sheets API
- From a web server
- To access application data
- Not using Google App Engine or Computer Engine
- Give it a service account name
- Don't give it a role
- Select the JSON key option
- Save that JSON file to some private folder where your code can access it.
- Get the Spreadsheet ID of the Google Sheet that you want to push data to. It is shown in its URL after the "https://docs.google.com/spreadsheets/d/" prefix, up until the next "/".
- Share that Google Sheet (cf. the spreadsheet ID) with the
client_email
value found in your Google credentials JSON file, giving it permission to edit the spreadsheet.
Viola! You should now be able to push data to that Google Sheet.
Testing
To test this library (and that your permissions are set up correctly)...
- Clone this repo to your local machine.
- Put your JSON credentials file in the "credentials" folder (Git is set to ignore that folder's contents... DO NOT COMMIT YOUR JSON FILE TO GIT).
- Copy the
local.env.dist
file tolocal.env
, giving it the requested values. - Open a terminal to the root of the repo and run
make
. - Look at your Google Sheet and verify that data has been appended.
Resources
How to use the Google PHP API Client (v1) that this uses:
Documentation on the append
Google Sheets API: