Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Google Drive文档上创建多个权限时出现Java异常_Java_Google App Engine_Google Api_Google Drive Api - Fatal编程技术网

在Google Drive文档上创建多个权限时出现Java异常

在Google Drive文档上创建多个权限时出现Java异常,java,google-app-engine,google-api,google-drive-api,Java,Google App Engine,Google Api,Google Drive Api,在我们的应用程序中,我们需要使用Google Drive api将多个文件共享给多个用户 我们使用GoogleDriveAPI的java客户端库提供的批处理 这已经在生产中运行,但是我们从Google Drive api中得到了很多不明确的例外: Internal Error. User message: "An internal error has occurred which prevented the sharing of these item(s): " 我们通过指数退避来处理异常和

在我们的应用程序中,我们需要使用Google Drive api将多个文件共享给多个用户

我们使用GoogleDriveAPI的java客户端库提供的批处理

这已经在生产中运行,但是我们从Google Drive api中得到了很多不明确的例外:

Internal Error. User message: "An internal error has occurred which prevented the sharing of these item(s): "

我们通过指数退避来处理异常和重试,但这些错误会导致此应用程序的流程和可用性出现严重延迟

发生这些异常的原因是什么?如何避免这些

如果我们知道发生这些异常时出现了什么问题,这将非常有帮助,这样我们就可以避免它

一些额外信息: 每个批包含对不同文件的100个权限操作。 每分钟调用一次批处理操作

守则:

String fileId = "1sTWaJ_j7PkjzaBWtNc3IzovK5hQf21FbOw9yLeeLPNQ";
JsonBatchCallback<Permission> callback = new JsonBatchCallback<Permission>() 
{
    @Override
    public void onFailure(GoogleJsonError e, HttpHeaders responseHeaders)
        throws IOException {
        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();

for(String email : emails) {
    Permission userPermission = new Permission().setType("user").setRole("reader").setEmailAddress(email);
    driveService.permissions().create(fileId, userPermission).setSendNotificationEmail(false).setFields("id").queue(batch, callback);
}

batch.execute();
String fileId=“1sTWaJ_j7PkjzaBWtNc3IzovK5hQf21FbOw9yLeeLPNQ”;
JsonBatchCallback callback=新的JsonBatchCallback()
{
@凌驾
失败时公开作废(Google JSonerror e、HttpHeaders负责人)
抛出IOException{
System.err.println(e.getMessage());
}
@凌驾
public void onSuccess(权限权限,HttpHeaders responseHeaders)引发IOException{
System.out.println(“权限ID:+Permission.getId());
}
};
BatchRequest batch=driveService.batch();
用于(字符串电子邮件:电子邮件){
权限userPermission=new Permission().setType(“用户”).setRole(“读者”).setEmailAddress(电子邮件);
driveService.permissions().create(fileId,userPermission).setSendNotificationEmail(false).setFields(“id”).queue(批处理,回调);
}
batch.execute();
变量emails包含100个电子邮件字符串

    {
    "code" : 500,
    "errors" : [ {
    "domain" : "global",
    "message" : "Internal Error. User message: "An internal                                                     error has occurred which prevented the sharing of these item(s): fileame"",
   "reason" : "internalError"
    } ],
  "message" : "Internal Error. User message: "An internal error has occurred which prevented the sharing of these item(s): filename""
    }
基本上是防洪。通常的建议是

指数退避是一种标准的网络错误处理策略 客户端定期重试失败请求的应用程序 在越来越多的时间里。如果大量请求或 严重的网络流量会导致服务器返回错误,如指数级错误 退避可能是处理这些错误的好策略。相反地 这不是一个处理与此无关的错误的相关策略 速率限制、网络容量或响应时间,如无效 未找到授权凭据或文件错误

如果使用得当,指数退避可以提高 带宽利用率,减少获取带宽所需的请求数 成功响应,并最大限度地提高中的请求吞吐量 并发环境

这就是你要说的,但我正在分批,我不能那样做。Yup配料属于相同的防洪保护范围。您的批处理正在淹没服务器。是的,我知道它说你可以发送100个请求,如果请求在每个请求之间花费足够的时间不符合洪水的条件,你可能可以发送,但是你的请求显然不符合洪水的条件


我的建议是你试着把它减少到10个请求,然后慢慢地增加。如果您没有使用批处理配额使用情况来保存任何内容,则与您没有批处理配额使用情况相同。您的速度不能超过洪水保护允许的速度。

欢迎使用stack,我们无法帮助调试无法查看和测试的代码。请编辑您的问题并添加一个问题:您每批发送多少个呼叫?您好,DalmTo,每批有100个呼叫。我将用代码编辑我的问题。谢谢你的回答。我会尝试一下,从每批100个请求,到10个,再到5个。每一批每分钟都在处理!!!即使在很长一段时间没有使用GoogleDrive api之后,我仍然会遇到同样的错误。在我看来,如果错误是关于洪水防护的,那么批处理根本不起作用……记住,你不是唯一一个攻击你所在服务器的人。您正在与其他开发人员竞争资源。如果运行批处理请求时出现500错误,请等待并再次发送,这就是实现指数退避的含义。或者停止使用批处理,我四年前就放弃了。这是针对v2的,它不是批处理,但它看起来像一个类似的问题嗨,谢谢。通过不使用批处理,它似乎适用于我的测试用例。我也将在应用程序上实现这一点。