Google sheets API v4 Create sheet and invite users

一曲冷凌霜 提交于 2019-12-01 17:31:35

A service account is a dummy user. It has its own drive account it owns the file it created on its account. The service account will need to give your personal google drive account access to said file. (Share it with you just like any other user)

Permissions: insert Inserts a permission for a file.

Note: You are currently authenticated to use the Google sheets API you are going to have to add google drive API (scope) to your code and your project on Google developers console. There is no way to change the permissions on a file via the google sheets API.

Yes you are going to have to add permissions for every member of your team who you want to allow to see / edit this file.

Tip: When you add google drive API try and do a files.list look for downloadUrl, alternateLink and embedLink in the results. Sometimes these are filled out and can be used for sharing viewable only to another user.

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;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!