Skip to content

Instantly share code, notes, and snippets.

@hdodov
Created January 9, 2020 12:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hdodov/16c72a143de0830072931ea4d7b01ace to your computer and use it in GitHub Desktop.
Save hdodov/16c72a143de0830072931ea4d7b01ace to your computer and use it in GitHub Desktop.
Script that appends rows to a spreadsheet via the Google Sheets API.
<?php
require __DIR__ . '/vendor/autoload.php';
$creds = 'credentials.json';
$sheedId = '1IMwiyCa1gCfh1lacyzZqFrYFsqCe-hOSRlaHIc2gFDw';
$range = 'Sheet1';
$client = new Google_Client();
$client->setAuthConfigFile($creds);
$client->useApplicationDefaultCredentials();
$client->addScope(Google_Service_Sheets::SPREADSHEETS);
$service = new Google_Service_Sheets($client);
$body = new Google_Service_Sheets_ValueRange([
'values' => [
['test@example.com', 42, true],
['foo@bar.net', 'hello', false]
]
]);
$params = [
'valueInputOption' => 'USER_ENTERED'
];
$result = $service->spreadsheets_values->append($sheedId, $range, $body, $params);
printf("%d cells appended.", $result->getUpdates()->getUpdatedCells());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment