I am using a service account authentication to create a google sheet using the Google Sheets API. I want to create a spreadsheet and somehow allow my team to open it.
It is possible to give permissions for domain accounts:
private function createNewSheet($title)
{
$properties = new \Google_Service_Sheets_SpreadsheetProperties();
$properties->setTitle($title);
$newSheet = new \Google_Service_Sheets_Spreadsheet();
$newSheet->setProperties($properties);
$response = $this->sheetService->spreadsheets->create($newSheet);
$fileId = $response['spreadsheetId'];
$domainPermission = new \Google_Service_Drive_Permission([
'type' => 'domain',
'role' => 'writer',
'value' => 'myCompany.com' //eg user@myCompany.com
]);
$this->driveService->permissions->insert($fileId, $domainPermission);
return $response;
}