我正在构建一个使用Google驱动器API的python应用程序,所以开发很好,但是我有一个问题需要检索整个Google驱动器文件树,我需要它有两个目的:
现在我有一个获取Gdrive根目录的函数,我可以通过递归调用一个函数来构建三个函数,这个函数列出了我单个文件夹的内容,但它非常慢并且可能会向Google发出数千个请求,这是不能接受的.
这里获取root的函数:
def drive_get_root():
"""Retrieve a root list of File resources.
Returns:
List of dictionaries.
"""
#build the service, the driveHelper module will take care of authentication and credential storage
drive_service = build('drive', 'v2', driveHelper.buildHttp())
# the result will be a list
result = []
page_token = None
while True:
try:
param = {}
if page_token:
param['pageToken'] = page_token
files = drive_service.files().list(**param).execute()
#add the files in the list
result.extend(files['items'])
page_token = files.get('nextPageToken')
if not page_token:
break
except …Run Code Online (Sandbox Code Playgroud)