0

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

1 Answer 1

1

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);
  });
}
Sign up to request clarification or add additional context in comments.

2 Comments

This assumes that the files.insert returned a files resource with the permissions so the app can grab a permissionId for permissions.patch. Given the bug (kudos for posting) and sparse documentation to confirm the behaviour, it's probably safer to assume the worst. Since he's making two calls anyway, I would probably suggest omitting permissions from the files.insert altogether and follow it up with a permissions.insert.
@pinoyyid that's what I normally do. I have tested it over and over and it permissions just don't get inserted. So I normally just patch after. Yes its an extra all but I don't see any other work around

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.