如何为存储在 Google 驱动器中的文件插入权限以与我域中的人共享

How to insert permissions for files stored in Google Drive to share it with people in my domain

我有一个 GSuite 帐户。我们通过 Web 应用程序将一些文件存储在 Google 驱动器上。我知道,我可以通过设置角色 'reader' 并使用 Google 驱动器 API 的 'permissions' 资源键入 'anyone' 来向文件添加权限 'Anyone with the link'。但是,我想在 Google 客户端库(PHP 库)的帮助下,为存储在 Google 驱动器中的文件添加权限,以便只允许我域中的人访问它。你能帮帮我吗?

我有一个 PHP 函数来为文件 ID

的文件插入权限
function insertPermission($service, $fileId, $value, $type, $role) {
    $newPermission = new Google_Service_Drive_Permission();
    $newPermission->setType($type);
    $newPermission->setRole($role);
    $newPermission->setWithLink(true);
    try {
        return $service->permissions->insert($fileId, $newPermission);
    } catch (Exception $e) {
        print "An error occurred: " . $e->getMessage();
    }
    return NULL;
}

Permissions.create 为文件或团队云端硬盘创建权限。

type string The type of the grantee. Valid values are:

  • user
  • group
  • domain
  • anyone

背景信息 普通驱动器帐户类型为 "type": "user", 您应将类型设置为域。

您可以将一些可选属性与我建议添加的请求一起发送。

domain The domain to which this permission refers.