Google sheets API 4: How to append to the end of t

2019-02-24 17:33发布

问题:

I am able to update a row by providing the range using the spreadsheets.values.update method, with the following the code:

$range = "A1:B1";
$valueRange= new Google_Service_Sheets_ValueRange();
$valueRange->setValues(["values" => ["a", "b"]]); 
$conf = ["valueInputOption" => "RAW"];
$service->spreadsheets_values->update($spreadsheetId, $range, $valueRange, $conf);

When using the spreadsheets.values.append method, with the following code:

$range = "A1:B";
$valueRange= new Google_Service_Sheets_ValueRange();
$valueRange->setValues(["values" => ["a", "b"]]); 
$conf = ["valueInputOption" => "RAW"];
$ins = ["insertDataOption" => "INSERT_ROWS"];
$service->spreadsheets_values->append($spreadsheetId, $range, $valueRange, $conf, $ins);

I get the following error message:

PHP Fatal error: Call to undefined method Google_Service_Sheets_Resource_SpreadsheetsValues::append()

What is wrong ?

回答1:

This was a case of the PHP client library being out of date. An updated version (2.0.3) is released now, and you can run composer update to retrieve it.