Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Phillip Shipley:
Read and write Google Sheets from PHP
Jun 01, 2017 @ 15:57:44

Phillip Shipley has written up a post for his site walking you through the process of using PHP to read from and write to Google Sheets via the Google Sheets API.

This past week I needed to be able to read some data from a Google Sheet and then update a column for each row after processing it. This sort of thing should be simple, Google is built on APIs and has client SDKs for just about every language. I’ve also integrated with several Google Admin APIs previously so I expected this to be a breeze. I was wrong.

I started out by reading the Quickstart for Sheets API with the PHP Client, but almost immediately I could tell it was not written for my use case. [...] My use case is to use a backend process to function as a service account and batch process data. So the whole API credentials process was wrong for me.

He tried a few different approaches and finally, after some guessing, discovered how to share a sheet with the email address for the application. He then includes the steps to follow to get this same setup configured for your application and the code (using the Google_Client) to read and write to the sheet.

tagged: read write google sheets tutorial client sharing

Link: http://www.phillipshipley.com/2017/05/read-and-write-google-sheets-from-php/

Twilio Blog:
Google Spreadsheets and PHP
Mar 08, 2017 @ 15:48:31

On the Twilio blog they've posted an article from Matt Stauffer looking at the combination of Google Sheets and PHP to perform some of the normal CRUD (create, read, update, delete) operations via the Google Sheets API.

Have you ever needed to pull some data from a Google Spreadsheet? My default in the past would be to export the data and upload it to the app directly, but it turns out it’s not very difficult to read directly from Google Spreadsheets using the Google Drive API.

In this tutorial, we’ll read, write, update, and delete data from a Google Spreadsheet with just a few lines of PHP.

He clones an example spreadsheet to use in the tutorial and shows how to prepare it for programatic access (basically exposing it for use). He then gets to work using the google/apiclient and asimlqt/php-google-spreadsheet-client packages to connect to and work with the API. He includes the code to:

  • connect to the API and get a usable token
  • pull data from the sheet by title
  • update individual cells data
  • updating entire rows
  • deleting rows
  • insert new rows

You'll need to be a bit familiar with how the Google API Console works to get things set up, but there's an animation that helps walk you through some of it.

tagged: google sheets tutorial package api crud operation console

Link: https://www.twilio.com/blog/2017/03/google-spreadsheets-and-php.html


Trending Topics: