Why Won#39;t Google API V3 Return Children?(为什么 Google API V3 不返回子级?)
问题描述
我想使用 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 不返回子级?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:为什么 Google API V3 不返回子级?


基础教程推荐
- 将 YAML 文件转换为 python dict 2022-01-01
- 哪些 Python 包提供独立的事件系统? 2022-01-01
- 症状类型错误:无法确定关系的真值 2022-01-01
- 如何在 Python 中检测文件是否为二进制(非文本)文 2022-01-01
- Python 的 List 是如何实现的? 2022-01-01
- 使用Python匹配Stata加权xtil命令的确定方法? 2022-01-01
- 如何在Python中绘制多元函数? 2022-01-01
- 合并具有多索引的两个数据帧 2022-01-01
- 使用 Google App Engine (Python) 将文件上传到 Google Cloud Storage 2022-01-01
- 使 Python 脚本在 Windows 上运行而不指定“.py";延期 2022-01-01