asimlqt / php-google-spreadsheet-client

A PHP library for accessing and manipulating Google Spreadsheets
Other
544 stars 152 forks source link

'Error in Google Request' exception when simulating newlines in request body #82

Closed ptrsec closed 8 years ago

ptrsec commented 9 years ago

I am sending data to a Google Spreadsheet and I have a cell where I want new lines between items, so I'm using:

="an_item"&CHAR(10)&"another_item"

And so on. The problem is I'm getting an exception. Here's the output:

( ! ) Fatal error: Uncaught exception 'Google\Spreadsheet\Exception' with message 'Error in Google Request' in Performance\vendor\asimlqt\php-google-spreadsheet-client\src\Google\Spreadsheet\DefaultServiceRequest.php on line 247 ( ! ) Google\Spreadsheet\Exception: Error in Google Request in Performance\vendor\asimlqt\php-google-spreadsheet-client\src\Google\Spreadsheet\DefaultServiceRequest.php on line 247 Call Stack 1 0.0030 255280 {main}( ) ..\index.php:0 2 61.2479 1048184 SpreadsheetService->addDataToReport( ) ..\index.php:29 3 63.4668 1221480 Google\Spreadsheet\CellFeed->editCell( ) ..\google.class.php:57 4 63.4669 1222200 Google\Spreadsheet\DefaultServiceRequest->post( ) ..\CellFeed.php:124 5 63.4670 1223512 Google\Spreadsheet\DefaultServiceRequest->execute( ) ..\DefaultServiceRequest.php:147

It seems that the HTTP response code is 400. I didn't further investigate the issue. Has anybody else encountered this issue and actually has a solution? I will come back with more details after debugging.

ptrsec commented 9 years ago

I found the issue. It's because of the double quotes, they won't get encoded and break the XML, so Google rejects it and throws a 400 status code. Converting the double quotes into their HTML entity representation should solve the problem (e.g. htmlentities() with the ENT_QUOTES parameter).

asimlqt commented 8 years ago

It's supported in the latest version