Why Won't Google API V3 Return Children?

左心房为你撑大大i 提交于 2020-12-01 10:15:02

问题


I want to use Python to get a list of all the files/folders in a given folder in Google Drive. The call I'm using is this:

query = parentID + " in parents"

response = service.files().list(q=query,
                                spaces='drive',
                                fields='files(id, name, parents)').execute()

According to the search for files documentation and the migrating to v3 documentation, I should be doing it correctly. But when I run the code, I get the following error:

<HttpError 400 when requesting https://www.googleapis.com/drive/v3/files?q=[MY_PARENT_ID]+in+parents&spaces=drive&alt=json&fields=files%28id%2C+name%2C+parents%29 returned "Invalid Value">

What is wrong with my query and how would I call this correctly?


回答1:


After trying for some 15 hours, found this solution:

just change the query variable as follows suppose parent id is '0B_hg54vjh34v5jh23gv5i2v35th2gv35v235kjvk'

query="'0B_hg54vjh34v5jh23gv5i2v35th2gv35v235kjvk' in parents"

now, it should work.

it should work even if you interchange single and double quotes..what you were using results into query="0B_hg54vjh34v5jh23gv5i2v35th2gv35v235kjvk in parents" while what we need is query="'0B_hg54vjh34v5jh23gv5i2v35th2gv35v235kjvk' in parents"

alternative way of doing this is:

parentId='0B_hg54vjh34v5jh23gv5i2v35th2gv35v235kjvk'
query="'" + "' in parents"

Why is this happening :-
If you look at your output error properly, It has a http link which looks like this:
https://www.googleapis.com/drive/v3/files?q=0B_hg54vjh34v5jh23gv5i2v35th2gv35v235kjvk+in+parents&spaces=drive&alt=json&fields=files%28id%2C+name%2C+parents%29


but the required one has single quotes around the Id and looks like this:
https://www.googleapis.com/drive/v3/files?q='0B_hg54vjh34v5jh23gv5i2v35th2gv35v235kjvk'+in+parents&spaces=drive&alt=json&fields=files%28id%2C+name%2C+parents%29



来源:https://stackoverflow.com/questions/36874223/why-wont-google-api-v3-return-children

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