Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google drive api 通过Google Drive SDK批量插入权限?_Google Drive Api - Fatal编程技术网

Google drive api 通过Google Drive SDK批量插入权限?

Google drive api 通过Google Drive SDK批量插入权限?,google-drive-api,Google Drive Api,Google Drive SDK是否支持权限的批处理操作(https://developers.google.com/drive/v2/reference/permissions/insert) 例如,我希望向20个用户授予文档的编写权限。 我可以通过1个REST呼叫而不是20个呼叫来完成吗?我刚刚看到了这个页面: 最后,我们可以看到驱动器API目前不支持批处理操作,尽管您可以通过编程实现这一点。我修改了他们的java脚本示例方法来实现它 /** * Retrieve a list o

Google Drive SDK是否支持权限的批处理操作(https://developers.google.com/drive/v2/reference/permissions/insert)

例如,我希望向20个用户授予文档的编写权限。
我可以通过1个REST呼叫而不是20个呼叫来完成吗?

我刚刚看到了这个页面:


最后,我们可以看到驱动器API目前不支持批处理操作,尽管您可以通过编程实现这一点。我修改了他们的java脚本示例方法来实现它

/**
     * Retrieve a list of permissions.
     *
     * @param {String} fileId ID of the file to retrieve permissions for.
     * @param {Function} callback Function to call when the request is complete.
     */
    function retrievePermissions(fileId, callback) {
      var request = gapi.client.drive.permissions.list({
        'fileId': fileId
      });
      request.execute(function(resp) {
        //console.log(resp);
        callback(resp.items);
      });
    }


/**
     * Update a permission's role.
     *
     * @param {String} fileId ID of the file to update permission for.
     * @param {String} permissionId ID of the permission to update.
     * @param {String} newRole The value "owner", "writer" or "reader".
     */
    function updatePermission(fileId, items,callback) {
        var updateRequest = gapi.client.drive.permissions.update({
          'fileId': fileId,
          'permissionId': items[0].id,
          'resource': items[0]
        });

        updateRequest.execute(function(resp) {
            items.splice(0,1);
            if (items.length > 0)
                updatePermission(fileId,items,callback);
            if (items.length == 0)
                callback(resp);
        });
    }
要调用这些方法,我有以下代码

retrievePermissions(result.id, function(items){
 var toUpdate = new Array();
 var j = 0;
 for (var i = 0; i < items.length; i++){
  if (items[i].role != "owner" && items[i].id != "anyoneWithLink"){
    items[i].role = "reader";
    items[i].additionalRoles = [ "commenter" ];
    toUpdate[j++] = items[i];
      }
     }

updatePermission(result.id, toUpdate, function(resp){ console.log (resp) } );
retrievePermissions(result.id,函数(项){
var toUpdate=新数组();
var j=0;
对于(变量i=0;i

}))

+1用于批次支持查询,但不是批次。在这里,您可以发送与权限插入一样多的请求。批处理将只是一个包含所有需要完成的事情的请求。