Cannot access Google Spreadsheet metadata by API

45 Views Asked by At

I have this code that tries to retrieve all data from a sheet , including metadata:

$response = $this->spreadsheet_service->spreadsheets->get($this->spreadsheet_id, ['ranges' => $sheet_name ]);
$sheetData = $response->getSheets();
foreach ($sheetData as $sheet) {
                    echo "sheet:";
                    var_dump($sheet);
                    $data = $sheet->getData();   
                    echo "sheet Data:";
                    var_dump($data);
                    die; 
}

The dump of $sheet shows me an object with rowCount = 996 , which means it's not empty. But the dump of $data shows:

sheet Data:array(0) { }

If i use $this->spreadsheet_service->spreadsheets_values , i can get all the values correctly , but i need a way to get metadata too , like each cell's last update time and coordinates. Maybe with my API credentials i cannot access metadata , that's why the code above won't work. Is there a permission i need to grant to my API user ? Or what else could be the problem? Thanks

1

There are 1 best solutions below

1
HelloWorld On BEST ANSWER

From my quick research , i've found out it's possible to achieve my goal by AppScripts + webhooks: https://medium.com/@eyalgershon/sending-a-webhook-for-new-or-updated-rows-in-google-sheets-e0c9d6a8cb45

In the AppScript function , one can get any metadata and pass it to the webhook , like current time , coordinates , etc.