Sumesh Kumar
Sumesh Kumar

Reputation: 41

Google drive permission issue while using Javascript API

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

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

Upvotes: 0

Views: 480

Answers (1)

Linda Lawton - DaImTo
Linda Lawton - DaImTo

Reputation: 116868

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);
  });
}

Upvotes: 1

Related Questions