Google Drive SDK是否支持批量操作权限(https://developers.google.com/drive/v2/reference/permissions/insert)
例如,我希望授予20个用户写入文档的权限。 我可以通过1次REST呼叫而不是20次呼叫来完成吗?
答案 0 :(得分:1)
我刚看到此页面:https://developers.google.com/drive/migration
最后,我们可以看到驱动器API目前不支持批处理操作
答案 1 :(得分:-1)
虽然您可以通过编程方式实现这一目标。我修改了他们的java脚本示例方法来实现它。
/**
* Retrieve a list of permissions.
*
* @param {String} fileId ID of the file to retrieve permissions for.
* @param {Function} callback Function to call when the request is complete.
*/
function retrievePermissions(fileId, callback) {
var request = gapi.client.drive.permissions.list({
'fileId': fileId
});
request.execute(function(resp) {
//console.log(resp);
callback(resp.items);
});
}
/**
* Update a permission's role.
*
* @param {String} fileId ID of the file to update permission for.
* @param {String} permissionId ID of the permission to update.
* @param {String} newRole The value "owner", "writer" or "reader".
*/
function updatePermission(fileId, items,callback) {
var updateRequest = gapi.client.drive.permissions.update({
'fileId': fileId,
'permissionId': items[0].id,
'resource': items[0]
});
updateRequest.execute(function(resp) {
items.splice(0,1);
if (items.length > 0)
updatePermission(fileId,items,callback);
if (items.length == 0)
callback(resp);
});
}
并调用这些方法我有以下代码。
retrievePermissions(result.id, function(items){
var toUpdate = new Array();
var j = 0;
for (var i = 0; i < items.length; i++){
if (items[i].role != "owner" && items[i].id != "anyoneWithLink"){
items[i].role = "reader";
items[i].additionalRoles = [ "commenter" ];
toUpdate[j++] = items[i];
}
}
updatePermission(result.id, toUpdate, function(resp){ console.log (resp) } );
});