Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Won't Google API V3 Return Children?

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?

like image 601
Elliptica Avatar asked Apr 26 '16 19:04

Elliptica


1 Answers

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

like image 172
Mridul Gupta Avatar answered Nov 07 '22 14:11

Mridul Gupta