简体   繁体   中英

Google drive permission issue while using Javascript API

We have an application where we are using Google drive API for creating

  • document
  • spreadsheet
  • slides

We have given the permission at the organization level in our Google administrative account. When I create a document its shows as People at our organization can view and access on top of the share button.

How ever when I create a spread sheet it initially shows as People at our organization can view and access , but when I close and open again its shows Private only to me .

I do not know why the permission is changing suddenly. I am not setting any permission while creating the document/sheet/slide. I am only calling the gapi.client.drive.files.insert

When you first insert a file even if you have set the permissions at insert they aren't always saved I think I have seen a bug report on this some place I will try and find it.

Issue 3717: Google drive api, upload file with shared permission

After you insert the file, do a patch on it, to update the permissions. Don't use file.update use patch

Code stolen from documentation:

/**
 * Patch a permission's role.
 *
 * @param {String} fileId ID of the file to update permission for.
 * @param {String} permissionId ID of the permission to patch.
 * @param {String} newRole The value "owner", "writer" or "reader".
 */
function patchPermission(fileId, permissionId, newRole) {
  var body = {'role': newRole};
  var request = gapi.client.drive.permissions.patch({
    'fileId': fileId,
    'permissionId': permissionId,
    'resource': body
  });
  request.execute(function(resp) {
    console.log('New Role: ' + resp.role);
  });
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM