简体   繁体   English

Python Google Drive API 未列出文件夹中的所有文件

[英]Python Google Drive API not listing all files in folder

One part of a program I am writing requires me to list the files and folders within a Google Drive folder.我正在编写的程序的一部分要求我列出 Google Drive 文件夹中的文件和文件夹。 I am currently using the following code:我目前正在使用以下代码:

page_token = None
while True:
    response = service.files().list(pageSize=1000,q="'folder_id' in parents",fields="nextPageToken, files(id, name)").execute()
    for file in response.get('files', []):
        print('Found file: %s (%s)' % (file.get('name'), file.get('id')))
    page_token = response.get('nextPageToken', None)
    if page_token is None:
        break

For some reason, one folder that I am testing returns only one file, even if I add additional files/folders, and every other parent folder_id I try results in no files being returned.出于某种原因,我正在测试的一个文件夹仅返回一个文件,即使我添加了其他文件/文件夹,并且我尝试的所有其他父 folder_id 都不会返回任何文件。 I even tried deleting the one file that is being returned, and it still gets returned when I call the function again.我什至尝试删除正在返回的一个文件,当我再次调用该函数时它仍然被返回。

If your are using service account which represent a service then:如果您正在使用代表服务的服务帐户,则:

  1. enable domain wide delegation for the service account.为服务帐户启用域范围的委派。 steps are and additionalinfo here.步骤和附加信息在这里。

  2. After enabling domain wide delegation ,share the desired folders which you want to list using your service/webapp with service account's email addressService account link , it would be something like "XXX...XXX.iam.gserviceaccount.com".启用域范围委派后,使用服务帐户的电子邮件地址服务帐户链接共享您要使用服务/网络应用列出的所需文件夹,它类似于“XXX...XXX.iam.gserviceaccount.com”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Google Drive API仅列出每个文件夹最多100个文件 - Google Drive API just listing up to 100 files per folder 列出 Python 中的所有 Google Drive 文件和文件夹并保存 ID - Listing all Google Drive files and folders in Python and save ID's 使用Drive API列出文件不会返回所有文件吗? - Listing files with Drive API is not returning all files? Google drive api python - 如何将文件夹或文件夹中的所有文件下载到特定的本地目标路径 - Google drive api python - How to download all the files inside a folder or the folder to a specific local destination path 从谷歌驱动器列出文件夹内容,也返回删除的文件 - Listing folder content from google drive, returns removed files too 列出Google驱动器文件时出错 - Error in listing the google drive files 使用python的谷歌驱动器文件夹中的文件列表 - List of files in a google drive folder with python 使用 Python API 表示 Google Drive 文件夹的文件和文件夹树 - representation of files and folder-tree of Google Drive folder using Python API Google Drive API - 监视文件夹的 Python 集成 - Google Drive API - Python Integration Watching A Folder Google Api/Python:上传新文件之前 Google Drive 中的空文件夹 - Google Api/Python: Empty folder in Google Drive before uploading new files
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM