[英]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:如果您正在使用代表服务的服务帐户,则:
enable domain wide delegation for the service account.为服务帐户启用域范围的委派。 steps are and additionalinfo here.
步骤和附加信息在这里。
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.