I am trying to create a new spreadsheet, which I understand is now possible in v4 of the API, but I don't see anything detailing how to create a sheet in the PHP documentation. I got:
$client->setApplicationName("Test");
$client->setScopes(['https://www.googleapis.com/auth/sheets']);
$service = new Google_Service_Sheets($client);
$service->spreadsheets->create();
But it expects parameter 1 to be an instance of Google_Service_Sheets_Spreadsheet, and I'm not sure what exactly I should provide.
Got it figured out. The sheet was created under the service account, not the primary account. Had to use the Drive API to add permissions to share with the primary account:
$client->setScopes(
['https://www.googleapis.com/auth/spreadsheets',
'https://www.googleapis.com/auth/drive']);
$service = new Google_Service_Sheets($client);
$drive = new Google_Service_Drive($client);
$ss = $service->spreadsheets->create(new Google_Service_Sheets_Spreadsheet());
$newPermission = new Google_Service_Drive_Permission();
$newPermission->setEmailAddress("[email protected]");
$newPermission->setType('user');
$newPermission->setRole('writer');
$optParams = array('sendNotificationEmail' => false);
$drive->permissions->create($ss->spreadsheetId,$newPermission,$optParams);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With