【发布时间】:2017-03-29 13:27:08
【问题描述】:
我正在使用适用于 PHP 的 Google API 客户端库(测试版)对 Google 表格进行更改。我想访问电子表格中的第一个工作表,然后对其进行更改。
$service = new Google_Service_Sheets($this->client);
$spreadsheet = $service->spreadsheets->get($google_sheet_id);
$sheets = $spreadsheet->getSheets();
使用上面的代码,我有一个 Google_Service_Sheets_Sheet 对象数组。如果我var_dump() 的内容,我可以在名为modelData 的受保护数组中看到我需要的属性。我想访问 sheetId 属性。
...
["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)
}
}
...
我已经尝试了所有我能想到的方法,包括标准的 PHP 魔术 get/set 语法,但没有任何效果。
$id = $sheets[0]->getSheetId(); // fails
$id = $sheets[0]->sheetId; // fails
$id = $sheets[0]->get('sheetId'); // fails
如何访问该对象的属性?
【问题讨论】:
标签: php google-analytics-api google-sheets-api