transfer file ownership in Google Drive API

…衆ロ難τιáo~ 提交于 2019-12-23 05:01:55

问题


I am trying to do transfering of file ownership to an emailaddress. I send this first request,

var body = {
    'emailAddress': value,
    'type': type,
    'role': "writer"
  };
  var request = gapi.client.drive.permissions.create({
    'fileId': fileId,
    'transferOwnership': false,
    'resource': body
  });
  request.execute(function(resp) { 
      ...
  });

This will create a permission writer for that emailaddress. After that, inside the request.execute() callback, I send the second request,

var request2 = gapi.client.drive.permissions.list({
      'fileId': fileId
    });
    body.role = role;
    request2.execute(function(resp2) { 
      var request3 = gapi.client.drive.permissions.update({
        'fileId': fileId,
        'permissionId': resp2.permissions[1].id, //permission id of writer
        'transferOwnership': true,
        'resource': {'role':role, 'emailAddress': value}
      });
      request3.execute(function(resp3) {
        console.log(resp3);
      });
    });

In the above request, I used permissions.list to get the file permission id. Then I used the permission id to update permissions. I used permissions.update request for transferOwnership. The problem I encountered here is "The user does not have sufficient permissions for this file."

What I am trying to do here is transfer the file ownership to an emailaddress. What is wrong with my codes? How can I transfer file ownership?


回答1:


You need to think about the old and new owners of the file. Unless they are in the same Google Accounts domain, (eg. foo@example.com as opposed to foo@gmail.com) you can't transfer ownership. Although it might sound inconvenient, there would be a clear security problem if this were to be allowed.

If they are in the same domain, confirm that you have a scope with sufficient privilege.



来源:https://stackoverflow.com/questions/42788967/transfer-file-ownership-in-google-drive-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!