本文介绍了GDrive禁用复制和下载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在没有高级驱动器服务的情况下管理共享功能:禁用复制和下载"?

How I can manage the sharing-feature: "Disable Copying and downloading" without the advanced Drive Service?

目前,我正在解决以下问题:

Currently I solve it about:

function mySolveAboutAdvancedService(id) {
  var file = Drive.Files.get(id);
  file.labels.restricted = true;
  Drive.Files.update(file, id);
}

为什么没有高级驱动器服务,我不能更改所有设置,而不能更改此设置?

Why I can change all settings but not this one without the advanced Drive Service?

谢谢

推荐答案

  • 您想在不使用高级Google服务的情况下实现以下脚本.

    • You want to achieve the following script without using Advanced Google services.

      var file = Drive.Files.get(id);
      file.labels.restricted = true;
      Drive.Files.update(file, id);
      

    • 您想知道没有使用上述脚本就无法实现禁用复制和下载"的原因.

    • You want to know the reason that "Disable Copying and downloading" cannot be achieved without using above script.

      如果我的理解是正确的,那么这个答案如何?请认为这只是几个可能的答案之一.

      If my understanding is correct, how about this answer? Please think of this as just one of several possible answers.

      高级Google服务的Drive API使用Drive API v2.在这种情况下, labels.restricted 适用于Drive API v2,并且,官方文档还说如下.

      Drive API of Advanced Google services uses Drive API v2. In this case, labels.restricted is for Drive API v2, and also, the official document says as follows.

      通过这种方式,当将 {labels:{restricted:true}} 用于Drive API v3时,将不会使用它,而不会发生任何错误.但是,当Drive API v2与UrlFetchApp一起使用时,仍可以使用 {labels:{restricted:true}} .这样,您的脚本就可以使用高级Google服务的Drive API了.

      By this, when {labels: {restricted: true}} is used for Drive API v3, it cannot be used while no error occurs. But, when Drive API v2 is used with UrlFetchApp, {labels: {restricted: true}} can be still used. By this, your script using Drive API of Advanced Google service works.

      为了在不使用高级Google服务的情况下实现脚本,请直接向Drive API v3(在本例中使用v3)的端点进行请求,请求正文为 {copyRequiresWriterPermission:true} 使用UrlFetchApp.示例脚本如下.

      In order to achieve your script without using Advanced Google services, please directly request to the endpoint of Drive API v3 (in this case, v3 is used.) with the request body of {copyRequiresWriterPermission: true} using UrlFetchApp. The sample script is as follows.

      function mySolveAboutAdvancedService() {
        var id = "###";  // Please set the file ID.
      
        var url = "https://www.googleapis.com/drive/v3/files/" + id;
        var params = {
          method: "patch",
          contentType: "application/json",
          payload: JSON.stringify({copyRequiresWriterPermission: true}),
          headers: {Authorization: "Bearer " + ScriptApp.getOAuthToken()}
        };
        var res = UrlFetchApp.fetch(url, params);
        Logger.log(res.getContentText())
      }
      

      注意:

      • 如果要将Drive API v2与UrlFetchApp一起使用,以下脚本如何?在Drive API v2中,可以同时使用 {labels:{restricted:true}} {copyRequiresWriterPermission:true} .

        function mySolveAboutAdvancedService() {
          var id = "###";  // Please set the file ID.
        
          var url = "https://www.googleapis.com/drive/v2/files/" + id;
          var params = {
            method: "put",
            contentType: "application/json",
            payload: JSON.stringify({copyRequiresWriterPermission: true}),  // or payload: JSON.stringify({labels: {restricted: true}})
            headers: {Authorization: "Bearer " + ScriptApp.getOAuthToken()}
          };
          var res = UrlFetchApp.fetch(url, params);
          Logger.log(res.getContentText())
        }
        

      • 如果我误解了你的问题,而这不是你想要的方向,我深表歉意.

        If I misunderstood your question and this was not the direction you want, I apologize.

        这篇关于GDrive禁用复制和下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 15:27