2

I'm trying to set permissions to several files in Google Drive using their API. I'd like to batch the insert permission API

So far, this is what I tried:

var httpBatch = gapi.client.newHttpBatch();

for(var fileIndex = 0; fileIndex < files.length; ++fileIndex) {
  httpBatch.add(
    gapi.client.request({
      path: 'drive/v2/files/' + files[fileIndex].id + '/permissions',
      method: 'POST',
      params: {
        value: 'some_user@gmail.com',
        type: 'user',
        role: 'writer'
      }
    })
  );
}

httpBatch.execute(callback);

I also tried to use the API "gapi.client.drive.permissions.insert" but I can't find a a way to do the batching properly with it.

I really hope this is possible. Anyway I would appreciate any help on this. Thanks a lot.

MPelletier
  • 16,256
  • 15
  • 86
  • 137
Thibaut
  • 81
  • 5

1 Answers1

2

Ok I got answers from Google guys, thanks a lot to them.

Here is how it should be done:

var httpBatch = gapi.client.newHttpBatch();

for(var fileIndex = 0; fileIndex < files.length; ++fileIndex) {
  httpBatch.add(
    gapi.client.request({
      path: 'drive/v2/files/' + files[fileIndex].id + '/permissions',
      method: 'POST',
      headers: {
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({
        value: 'some_user@gmail.com',
        type: 'user',
        role: 'writer'
      })
    })
  );
}
Thibaut
  • 81
  • 5