Created
January 9, 2020 12:40
-
-
Save hdodov/16c72a143de0830072931ea4d7b01ace to your computer and use it in GitHub Desktop.
Script that appends rows to a spreadsheet via the Google Sheets API.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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