Non latin symbols in setQ(query) in Google Drive API V2

青春壹個敷衍的年華 提交于 2019-12-14 03:44:26

问题


I have Google Drive with two folders in the root - with latin and non latin (cyrillic) names:

When I search the Google Drive root with a

String query = "'root' in parents and title='Archive' and trashed=false"; 
drive.files().list().setQ(query).execute()

it gives me a metadata of Archive folder as on picture below:

But if I change query string to 'root' in parents and title='Архив' and trashed=false (with Cyrillic folder name) it gives me nothing:

I am using V2 of Google Drive API by means of following libs:

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

Is it a bug or should I use some encoding for non latin characters in the searched name? If last where does Google mention it in their docs!?

UPDATE FOR V3 The problem remains. Checked against following libs:

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

SECOND UPDATE: Some research with API Explorer V2 shows that the problem is in Russian capital letters. If there is atleast one capital letter in folder name: 'root' in parents and title='папкА' and trashed=false a query with such folder name gives nothing:

{
 "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": []
}

If capital letters are absent in folder name: 'root' in parents and title='папки' and trashed=false query returns correct json with folder metadata. The same is for V3. Therefore the problem is in Drive server.

THIRD UPDATE: Query 'root' in parents and title contains 'папкА' and trashed=false returns a correct answer!


回答1:


For your use case, I've tried latin symbols in Drive API version 3 Try-it and I think it works.

So I have this folder named "ɞʚᵷ" which I hope is a Latin symbol and did a query.

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

It works!

response:

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

Updated: I've tried naming my folder in Russian like the one you're using - "Архив", and I had the same result, empty results. I think this is Drive's limitation. Kindly use English alphabet to ensure that the query always works.



来源:https://stackoverflow.com/questions/45563371/non-latin-symbols-in-setqquery-in-google-drive-api-v2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!