I am working on an app that reads and updates values in a Google Spreadsheet using Google Sheets API. I am able to read using my developer key, however attempting to write returns this error:
"Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential."
Read (works fine):
$client = new Google_Client();
$client->setApplicationName("XXX");
$client->setDeveloperKey("XXX");
$service = new Google_Service_Sheets($client);
$spreadsheetId = "XXX";
$range = 'promocodes';
$response = $service->spreadsheets_values->get($spreadsheetId, $range);
$values = $response->getValues();
Write code (error):
$client = new Google_Client();
$client->setApplicationName("XXX");
$client->setDeveloperKey("XXX");
$service = new Google_Service_Sheets($client);
$spreadsheetId = "XXX";
$range = 'promocodes!C4';
$values = [1];
$body = new Google_Service_Sheets_ValueRange([
'values' => $values
]);
$params = [
'valueInputOption' => $valueInputOption
];
$result = $service->spreadsheets_values->update($spreadsheetId, $range,
$body, $params);
printf("Cells updated.", $result->getUpdatedCells());