I'm using the Google API Client Libraries for PHP (Beta) to make changes to a Google Sheet. I would like to access the first worksheet in the spreadsheet and then make changes to it.
$service = new Google_Service_Sheets($this->client);
$spreadsheet = $service->spreadsheets->get($google_sheet_id);
$sheets = $spreadsheet->getSheets();
Using the code above I have an array of Google_Service_Sheets_Sheet
objects. If I var_dump()
the contents I can see the property I need in the protected array called modelData. I want to access the sheetId property.
...
["modelData":protected]=>
array(3) {
["properties"]=>
array(5) {
["sheetId"]=>
int(123456789)
["title"]=>
string(15) "Page Popularity"
["index"]=>
int(0)
["sheetType"]=>
string(4) "GRID"
["gridProperties"]=>
array(2) {
["rowCount"]=>
int(4)
["columnCount"]=>
int(4)
}
}
...
I've tried everything I can think of including the standard PHP magic get/set syntax and nothing works.
$id = $sheets[0]->getSheetId(); // fails
$id = $sheets[0]->sheetId; // fails
$id = $sheets[0]->get('sheetId'); // fails
How do I access properties on this object?