为什么 Google API V3 Return Children?

Why Won't Google API V3 Return Children?

我想使用 Python 获取 Google 驱动器中给定文件夹中所有 files/folders 的列表。我正在使用的电话是这样的:

query = parentID + " in parents"

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

根据 search for files documentation and the migrating to v3 文档,我应该是正确的。但是当我 运行 代码时,出现以下错误:

<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">

我的查询有什么问题,我该如何正确调用它?

尝试了大约 15 个小时后,找到了这个解决方案:

只需更改 query 变量如下 假设父 ID 是 '0B_hg54vjh34v5jh23gv5i2v35th2gv35v235kjvk'

query="'0B_hg54vjh34v5jh23gv5i2v35th2gv35v235kjvk' in parents"

现在,应该可以了。

即使你交换单引号和双引号它也应该工作..你使用的结果变成 query="0B_hg54vjh34v5jh23gv5i2v35th2gv35v235kjvk in parents" 而我们需要的是 query="'0B_hg54vjh34v5jh23gv5i2v35th2gv35v235kjvk' in parents"

另一种方法是:

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

为什么会这样:-
如果您正确查看输出错误, 它有一个 http link,看起来像这样:
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 在 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