更新:此问题似乎已得到解决。有关详细信息,请参阅bug tracker report。
我在通过Drive REST API(v3)获取文件列表请求时遇到了一些困难
内部服务器错误(错误代码500.)我试图使用name
和appProperties
键调用
排序顺序为files().list()
和name
的搜索条件中的createdTime
。 (这是"案例1" in
下面的代码。)我正在使用的语法记录为here。
为了解决问题,我采用了Google Drive API> REST Android快速入门项目
找到here并对其进行了一些修改
getDataFromApi
方法,如下面的代码块所示。
使用搜索条件和排序顺序字段的各种组合有六个测试用例。有些查询成功了 其他人用服务器代码500失败并且一次失败。这些结果在运行Android 7.0的模拟器上是一致的 使用API 24.我的问题源自早期版本。
我最感兴趣的是获得案例1的解决方案,并提供其他案例作为我试图弄清楚出了什么问题。对于我可能做错了什么或者其他可能发生的事情,我将不胜感激。
private List<String> getDataFromApi() throws IOException {
// Get a list of up to 10 files.
List<String> fileInfo = new ArrayList<String>();
/* Case 1: Crashes with following error:
500 Internal Server Error
{
"code" : 500,
"errors" : [ {
"domain" : "global",
"message" : "Internal Error",
"reason" : "internalError"
}],
"message" : "Internal Error"
} */
String query = "name contains 'Test' and not appProperties has {key='X' and value='Y'}";
String orderBy = "name, createdTime";
// Case 2: Succeeds and lists files.
// Like case 1, but "createdTime is dropped in sort order.
// String query = "name contains 'Test' and not appProperties has {key='X' and value='Y'}";
// String orderBy = "name";
// Case 3: Succeeds and lists files.
// Like case 1, but appProperties criteria is dropped.
// String query = "name contains 'Test'";
// String orderBy = "name, createdTime";
// Case 4: Times out.
// Like case 1, but the name criteria is dropped.
// String query = "not appProperties has {key='X' and value='Y'}";
// String orderBy = "name, createdTime";
// Case 5: Errors out like case 1.
// Like case 4, but the selection query is inverted.
// String query = "appProperties has {key='X' and value='Y'}";
// String orderBy = "name, createdTime";
// Case 6: Succeeds and lists files.
// Like case 4, but name is dropped in sort order.
// final String query = "not appProperties has {key='X' and value='Y'}";
// final String orderBy = "createdTime";
FileList result = mService.files().list()
.setPageSize(10)
.setFields("nextPageToken, files(id, name)")
// following was added
.setOrderBy(orderBy)
.setQ(query)
// end added code
.execute();
List<File> files = result.getFiles();
if (files != null) {
for (File file : files) {
fileInfo.add(String.format("%s (%s)\n",
file.getName(), file.getId()));
}
}
return fileInfo;
}
答案 0 :(得分:1)
回复的主要编辑:
我认为您应该将此报告为Google的错误。我一直在玩它,我不能让appProperties
作为file.list的一部分返回,就像文件资源不包含该字段一样,所以你从search收到错误。即使我将字段设置为*也应该返回文件resource的所有字段,这也是如此。
当您举报时,向他们发送您的示例apps-api-issues也会链接此问题。将您的问题请求链接回此处,我会看到我是否可以在Google云端硬盘上找到某人来ping它。
答案 1 :(得分:0)
指数退避仅适用于错误是暂时的。这只会偶尔发生,例如。当数据中心出现中断时。
很多500个错误都是GDrive中的错误,其中无效(或偶尔,偶数) 有效的)请求正在被错误地处理。我建议您使用https://developers.google.com/drive/v3/reference/files/list#try-it来确保您的查询字符串正确形成,引用等等。