【问题标题】:Non latin symbols in setQ(query) in Google Drive API V2Google Drive API V2 中的 setQ(query) 中的非拉丁符号
【发布时间】:2017-08-08 08:37:49
【问题描述】:

我的 Google Drive 在根目录中有两个文件夹 - 带有拉丁和非拉丁(西里尔文)名称:

当我使用

搜索 Google Drive 根目录时
String query = "'root' in parents and title='Archive' and trashed=false"; 
drive.files().list().setQ(query).execute()

它给了我Archive 文件夹的元数据,如下图所示:

但如果我将查询字符串更改为 'root' in parents and title='Архив' and trashed=false(带有西里尔文文件夹名称),它什么也没给我:

我正在通过以下库使用 Google Drive API 的 V2

com.google.apis:google-api-services-drive:v2-rev154-1.18.0-rc
com.google.api-client:google-api-client:1.18.0-rc
com.google.api-client:google-api-client-android:1.18.0-rc
com.google.http-client:google-http-client:1.18.0-rc
com.google.http-client:google-http-client-gson:1.18.0-rc

这是一个错误还是我应该对搜索名称中的非拉丁字符使用某种编码?如果最后 Google 在他们的文档中提到它!?

V3 更新 问题依然存在。检查以下库:

com.google.apis:google-api-services-drive:v3-rev80-1.22.0
com.google.api-client:google-api-client:1.22.0
com.google.api-client:google-api-client-android:1.22.0
com.google.http-client:google-http-client:1.22.0
com.google.http-client:google-http-client-gson:1.22.0

第二次更新:API Explorer V2 的一些研究表明问题出在俄语大写字母上。如果文件夹名称中至少有一个大写字母:'root' in parents and title='папкА' and trashed=false 具有此类文件夹名称的查询不会给出任何结果:

{
 "kind": "drive#fileList",
 "etag": "\"iqKjQ5Hr8wRO8SSHNW8KBrJOqxI/skD00QgZZ0FB6U5ufzrrxrFjqyA\"",
 "selfLink": "https://www.googleapis.com/drive/v2/files?q='root'+in+parents+and+title%3D'%D0%BF%D0%B0%D0%BF%D0%BA%D0%90'+and+trashed%3Dfalse",
 "incompleteSearch": false,
 "items": []
}

如果文件夹名称中没有大写字母:'root' in parents and title='папки' and trashed=false 查询返回正确的 json 和文件夹元数据。 V3 也是如此。 因此问题出在云端硬盘服务器上

第三次更新:查询'root' in parents and title contains 'папкА' and trashed=false返回正确答案!

【问题讨论】:

  • @noogui 你的意思是要避免在文件夹名称中使用非拉丁字符!?
  • 如果在您询问drive.files().get(folderId).execute() 时显示带有非拉丁字符的项目,我们为什么要避免使用几乎相同的查询drive.files().list().setQ(query).execute() 找到它们?我想谷歌应该解决这个问题。
  • 我的意思是 - 如果当您询问 drive.files().list().setQ("'root' in parents and trashed=false").execute() 时显示带有非拉丁字符的项目,我们为什么要避免使用几乎相同的查询 drive.files().list().setQ("'root' in parents and title='Архив' and trashed=false").execute() 找到它们?看起来不合理。我想 Google 应该解决这个问题。
  • 我建议首先确定这是库问题还是 Google Drive 问题,因此请尝试使用 curl 的原始 http 调用来使其正常工作,即。忽略该库,使用原始 http,您至少可以控制字符集 http 标头进行实验。一旦你让它与 curl 一起工作,然后弄清楚如何使库以相同的方式运行。您甚至可能需要修补库或提交 PR。
  • 据我了解 noogui 在下面的答案中做出了 curl 并且它有效。我认为这是图书馆的问题。

标签: android google-drive-api google-drive-android-api drive


【解决方案1】:

对于您的用例,我在Drive API version 3 Try-it 中尝试了拉丁符号,我认为它有效。

所以我有一个名为“ɞʚᵷ”的文件夹,我希望它是一个拉丁符号并进行了查询。

name contains 'ɞʚᵷ' and mimeType = 'application/vnd.google-apps.folder'

有效!

回复:

{
 "kind": "drive#fileList",
 "incompleteSearch": false,
 "files": [
  {
   "kind": "drive#file",
   "id": "0Bzgk4zccNwI7TFhPLUpGdmlmVVE",
   "name": "ɞʚᵷ",
   "mimeType": "application/vnd.google-apps.folder"
  }
 ]
}

更新: 我试过用俄语命名我的文件夹,就像你正在使用的那样 - “Архив”,我得到了相同的结果,结果是空的。我认为这是Drive的限制。请使用英文字母以确保查询始终有效。

【讨论】:

  • 你能试试name='ɞʚᵷ' and mimeType = 'application/vnd.google-apps.folder'against V3吗?
  • 谢谢!如果没有人建议 V2 的解决方案,我会接受你的回答。你能在 AS 中展示设置为使用 V3 和 Gradle 的库吗?
  • AS 在应用程序脚本中?建议您使用 Drive V3。
  • AS - Android Studio。
  • 好吧,这里有Android REST Quickstart 和专用的Drive Android API
猜你喜欢
  • 2012-11-12
  • 1970-01-01
  • 1970-01-01
  • 2011-07-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-27
  • 2011-02-15
  • 2020-04-10
相关资源
最近更新 更多