对于我们的应用程序,我们使用具有 2 足授权的 Google Drive SDK。
我们使用 Drive SDK 很长时间了,但今天我们遇到了 Files.list API 的新问题(https://developers.google.com/drive/v2/reference/files/list https://developers.google.com/drive/v2/reference/files/list)。对于来自不同域的某些用户,我们收到以下错误:
{“错误”:{“代码”:500,“消息”:空}}
Drive SDK 一切正常吗?这个错误是什么意思?
我建议阅读此内容post https://stackoverflow.com/a/13543366/453348这帮助我使用 Android 配置并连接到 Google Drive
EDIT:
我有相同的 500 错误服务器,为了避免这个错误 Google 推荐Exponential backoff https://developers.google.com/drive/manage-uploads?hl=en#exp-backoff据他们说:
指数退避是网络的标准错误处理策略
客户端定期重试失败请求的应用程序
在越来越长的时间内。如果请求量很大或
网络流量过大导致服务器返回错误,呈指数级增长
退避可能是处理这些错误的一个好策略。反过来,
它不是处理与以下内容无关的错误的相关策略
速率限制、网络量或响应时间,例如无效
授权凭据或文件未找到错误。
使用得当,指数退避可以提高效率
带宽使用,减少了获取数据所需的请求数量
成功响应,并最大化请求的吞吐量
并发环境。
Example:
安卓代码:
FileList files = null;
for (int n = 0; n < 5; ++n) {
try {
setStatus("trying n = " + n);
files = service.files()
.list()
.setMaxResults(1)
.setQ("mimeType = 'application/vnd.google-apps.folder' and title = 'folder_title'")
.execute();
}
catch (GoogleJsonResponseException e)
{
if (e.getDetails().getCode() == 500) {
try {
Thread.sleep((1 << n) * 1000 + randomGenerator.nextInt(1001));
setStatus("sleep() n = " + n);
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
setStatus("InterruptedException n = " + n + " " + e1.getMessage());
e1.printStackTrace();
}
}
}
}
我已经测试了这段代码,在最后一次尝试中它连接成功
Google 建议对 4xx 和 5xx 服务器使用指数退避error https://developers.google.com/drive/handle-errors
The 4xx 服务器 https://developers.google.com/drive/handle-errors#implementing_exponential_backoff错误主要是身份验证问题
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)