問題描述
我想使用 Python 獲取 Google Drive 中給定文件夾中所有文件/文件夾的列表.我正在使用的電話是這樣的:
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()
根據搜索文件文檔和遷移到 v3 文檔,我應該做的正確.但是當我運行代碼時,出現以下錯誤:
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?
推薦答案
試了15個小時,找到了這個解決方案:
After trying for some 15 hours, found this solution:
只需改變 query 變量如下假設父 id 是 '0B_hg54vjh34v5jh23gv5i2v35th2gv35v235kjvk'
just change the query variable as follows suppose parent id is '0B_hg54vjh34v5jh23gv5i2v35th2gv35v235kjvk'
query="'0B_hg54vjh34v5jh23gv5i2v35th2gv35v235kjvk' in parents"
現在,它應該可以工作了.
now, it should work.
即使你交換單引號和雙引號它也應該工作..你使用的結果是 query="0B_hg54vjh34v5jh23gv5i2v35th2gv35v235kjvk in parents"
而我們需要的是 query="'0B_hg54vjh34v5jh23gv5i2v35th2gv35v235kjvk'在父母中"
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"
另一種做法是:
parentId='0B_hg54vjh34v5jh23gv5i2v35th2gv35v235kjvk'
query="'" + "' in parents"
為什么會這樣:-
如果您正確查看輸出錯誤,它有一個如下所示的 http 鏈接:https://www.googleapis.com/drive/v3/files?q=0B_hg54vjh34v5jh23gv5i2v35th2gv35v235kjvk+in+parents&spaces=drive&alt=json&fields=files%28id%2C+name%2C+parents%29
但所需的 Id 周圍有單引號,如下所示:https://www.googleapis.com/drive/v3/files?q='0B_hg54vjh34v5jh23gv5i2v35th2gv35v235kjvk'+in+parents&spaces=drive&alt=json&fields=files%28id%2C+name%2C+parents%29
這篇關于為什么 Google API V3 不返回子級?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!