Skip to content

Instantly share code, notes, and snippets.

@hdodov
Created January 9, 2020 12:40
Show Gist options
  • 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' => [
['[email protected]', 42, true],
['[email protected]', '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