【问题标题】:Hide share option from Google doc从 Google 文档中隐藏共享选项
【发布时间】:2015-11-03 21:22:10
【问题描述】:

我正在使用 .NET SDK for google drive api 在 Google Drive 上上传/创建文件。一切正常,我可以根据我的业务逻辑向用户授予权限,如作者、读者、评论者或所有者。但我想对除所有者之外的所有人隐藏“共享”按钮,因为我的业务逻辑应决定应与谁共享哪个文件以及何时共享。

这是共享文档的代码:

try
{
 Google.Apis.Drive.v2.Data.Permission permission = new Google.Apis.Drive.v2.Data.Permission();
switch (role)
            {
                case GoogleRoles.WRITER:
                case GoogleRoles.READER:
                case GoogleRoles.OWNER:
                    {
                        permission.Role = role;
                        permission.Value = userEmail;
                        permission.Type = "user";
                        break;
                    }
                case GoogleRoles.COMMENTER:
                    {
                        permission.Role = GoogleRoles.READER;  //Need to assign role before we assign the additional role of commenter.
                        List<String> additionalRoles = new List<string>();
                        additionalRoles.Add(GoogleRoles.COMMENTER);
                        permission.AdditionalRoles = additionalRoles;
                        permission.Type = "user";
                        permission.Value = userEmail;
                        break;
                    }
            }

PermissionsResource.InsertRequest insertRequest = DriveService.Permissions.Insert(permission, fileId);
insertRequest.SendNotificationEmails = true;
insertRequest.Execute();

其中DriveService 是服务帐户的一个实例。任何指针都会有很大帮助。

【问题讨论】:

  • @DalmTo 你对此有什么想法吗?

标签: c# google-drive-api google-api-dotnet-client service-accounts


【解决方案1】:

很遗憾,Drive API 尚不支持禁用共享或禁用下载的功能。请在此处提交功能请求:https://code.google.com/a/google.com/p/apps-api-issues/issues/entry?template=Feature%20request&labels=Type-Enhancement,API-Drive

【讨论】:

【解决方案2】:

我已将此作为增强功能提出,也得到了回应。所以在 Google drive API 中,它不是权限的一部分,而是文件本身的属性,所以我们需要设置他的属性而不是权限,例如:

File.LabelsData labels = new File.LabelsData();
labels.Restricted = true;
File body = new File();
body.Labels = labels;
body.WritersCanShare = false;

解决了Share 的问题,但下载问题并没有通过上述更改解决。有关这方面的更多详细信息,请访问https://developers.google.com/drive/v2/reference/files

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-12-09
    • 2023-02-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多