I have a webpage that posts requests to update a Google spreadsheet cell to a php script. It is using the asimlqt/php-google-spreadsheet-client/ PHP wrapper for the Google Spreadsheet API. Most of the time, it works fine. For a few cells, though, it gives me an 'Error in Google Request' error. I investigated and found that the http_code being returned is 400.
I can't figure out what could be different about the cells where update doesn't work. They hold free-form text entered through a Google form, but the cells that have problems are not the ones with the longest text, and there aren't any strange characters. There are more than 100 rows, and I've only found a few where I get this problem, and so far I've only seen the problem with cells in one column, so I'm pretty sure the credentials are ok.
The error comes from the function:
function updateCell($row, $col, $val) { global $cellFeed; try { $cellFeed->editCell($row+2, $col+1, $val); } catch (Exception $e) { output('ERROR (updateCell): ' . $e->getMessage()); return false; } return true; } and the $cellFeed comes from
$serviceRequest = new Google\Spreadsheet\DefaultServiceRequest($accessToken); Google\Spreadsheet\ServiceRequestFactory::setInstance($serviceRequest); $spreadsheetService = new Google\Spreadsheet\SpreadsheetService(); $spreadsheet = $spreadsheetService->getSpreadsheetById($SPREADSHEET_ID); $worksheetFeed = $spreadsheet->getWorksheets(); $worksheet = $worksheetFeed->getByTitle($WORKSHEET_NAME); $cellFeed = $worksheet->getCellFeed();
$col+1when you're callingeditCellso I am curious whether the range might be undefined.