var request = gapi.client.drive.permissions.insert({
fileId: fileId,
resource: {
value:"user@gmail.com",
type:"user",
role:"reader"
}
});
此代码向共享一个文件的“user@gmail.com”发送了一封电子邮件:如何在一次/一封电子邮件中对多个fileId执行相同操作?
在https://developers.google.com/drive/v2/reference/permissions/insert#request
找不到答案答案 0 :(得分:0)
您似乎需要为多个权限执行batch requests。驱动文档说明:
我们强烈建议您使用批量请求来修改多个 权限。
以下是Java中批量请求的摘录:
String fileId = "1sTWaJ_j7PkjzaBWtNc3IzovK5hQf21FbOw9yLeeLPNQ";
JsonBatchCallback<Permission> callback = new JsonBatchCallback<Permission>() {
@Override
public void onFailure(GoogleJsonError e,
HttpHeaders responseHeaders)
throws IOException {
// Handle error
System.err.println(e.getMessage());
}
@Override
public void onSuccess(Permission permission,
HttpHeaders responseHeaders)
throws IOException {
System.out.println("Permission ID: " + permission.getId());
}
};
BatchRequest batch = driveService.batch();
Permission userPermission = new Permission()
.setType("user")
.setRole("writer")
.setEmailAddress("example@appsrocks.com");
driveService.permissions().create(fileId, userPermission)
.setFields("id")
.queue(batch, callback);
Permission domainPermission = new Permission()
.setType("domain")
.setRole("reader")
.setDomain("appsrocks.com");
driveService.permissions().create(fileId, domainPermission)
.setFields("id")
.queue(batch, callback);
batch.execute();