GOOGLE HAS BEEN SENDING OUT MESSAGES SAYING THAT SEVERAL OF THEIR APIS ARE GOING TO BE DISCONTINUED (FOR EXAMPLE, THE DOCUMENT LIST API). AS A RESULT, I TRIED TO MODIFY MY CUSTOM GOOGLE SPREADSHEET-POPULATING PHP SCRIPT TO USE THE NEW DRIVE API. AFTER WAY TOO MUCH WASTED TIME, I DISCOVERED THAT THE DRIVE API CAN CREATE SHEETS AND READ THEIR METADATA, BUT CAN’T ADD ROWS — FOR THAT WE CAN KEEP USING THE SPREADSHEETS API.
I was successful at converting the authentication portion of my script from the old ClientLogin to OAuth with a Service Account (the script runs behind the scenes of a web site and populates a Google spreadsheet that the web site user has no knowledge of).
It wasn’t as simple as I’d hoped because the Google-provided PHP client for the Drive API doesn’t know about the Spreadsheets API. I had to dig around the PHP libraries to piece together authentication codes and Google_Http_Requests.
So, if anyone else out there is interested in the combination of PHP, the Spreadsheets API, and OAuth with Service Accounts, this could save you some time.
The code is available in a public Gist at https://gist.github.com/karlkranich/cbbfbdf5825217b2976f
Here are the step-by-step instructions to get this to work:
Create the Service Account
Create a Spreadsheet and share with the Service Account
Get the PHP Drive API Client
git clone https://github.com/google/google-api-php-client.git google-api-php-client