看来您最近将 API 版本从 2 升级到了 3!根据Drive API changelog,不再有children() 资源。我怀疑还有其他您没有预料到的更改,因此请务必查看该更改日志。
来自Drive V3 的 Python 客户端库文档的一些有用信息:
about() 返回 about 资源。
changes() 返回更改资源。
channels() 返回渠道资源。
comments() 返回 cmets 资源。
files()返回文件资源。
permissions() 返回权限资源。
replies() 返回回复资源。
revisions() 返回修订资源。
teamdrives() 返回团队驱动资源。new_batch_http_request()根据发现文档创建BatchHttpRequest对象。
如果你不想迁移,children() 资源还有Drive V2:
about() 返回 about 资源。
apps() 返回应用资源。
changes() 返回更改资源。
channels() 返回渠道资源。
children()返回子资源。
comments() 返回 cmets 资源。
files() 返回文件资源。
parents() 返回父资源。
permissions() 返回权限资源。properties() 返回属性资源。
realtime() 返回实时资源。
replies() 返回回复资源。
revisions() 返回修订资源。
teamdrives() 返回teamdrives 资源。
new_batch_http_request() 根据发现文档创建BatchHttpRequest 对象。
那么,您的解决方案是构建 Drive REST API 的 V2 版本:
service = build('drive', 'v2', ...)
或继续使用v3 并更新您的代码以使用现在需要的files() 资源。
您可以使用正确的参数请求具有 id folderId 的文件夹的子级并调用 list 和 list_next:
Python3 代码:
kwargs = {
"q": "'{}' in parents".format(folderId),
# Specify what you want in the response as a best practice. This string
# will only get the files' ids, names, and the ids of any folders that they are in
"fields": "nextPageToken,incompleteSearch,files(id,parents,name)",
# Add any other arguments to pass to list()
}
request = service.files().list(**kwargs)
while request is not None:
response = request.execute()
# Do stuff with response['files']
request = service.files().list_next(request, response)
参考资料: