在Google Drive API中传输文件所有权 [英] transfer file ownership in Google Drive API

查看:454
本文介绍了在Google Drive API中传输文件所有权的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将文件所有权转让给电子邮件地址。
我发送这个第一个请求,

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

这将为该电子邮件地址创建一个许可作者。
之后,在request.execute()回调中,
发送第二个请求,

  var request2 = gapi.client.drive.permissions.list({
'fileId':fileId
});
body.role =角色;
request2.execute(function(resp2){
var request3 = gapi.client.drive.permissions.update({$ b $'fileId':fileId,$ b $'permissionId':resp2 .permissions [1] .id,//作者的权限ID
'transferOwnership':true,
'resource':{'role':role,'emailAddress':value}
} );
request3.execute(function(resp3){
console.log(resp3);
});
});

在上面的请求中,我使用了permissions.list来获取文件权限ID。
然后我使用权限ID来更新权限。我使用permissions.update请求transferOwnership。我在这里遇到的问题是用户没有足够的权限来访问此文件。



我在这里要做的是将文件所有权转移到电子邮件地址。我的代码有什么问题?我怎样才能传输文件的所有权?

解决方案

您需要考虑文件的新旧所有者。除非它们位于相同的Google帐户域中(例如,foo@example.com而不是foo@gmail.com),否则您不能转让所有权。虽然这可能听起来不方便,但如果允许的话,会有明显的安全问题。



如果它们位于同一个域中,请确认您有一个范围足够的特权。

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?

解决方案

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.

这篇关于在Google Drive API中传输文件所有权的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆