[英]Not getting list of items in shared folders with Google Drive API
我试图在 Python 中获取 Google Drive API 的文件夹列表。我可以在我的驱动器文件夹中获取该列表,但我无法获取共享文件夹的项目列表。 我使用 GCP 服务帐户作为凭据,并且我已经将服务帐户设置到共享文件夹中。 谁有解决办法?? 我应该使用另一个参数吗? 太感谢了。
drive = build('drive', 'v3', credentials=credentials)
folderId = "xxxxxxxxxxx"
query = f"parents = '{folderId}'"
response = drive.files().list(q=query,includeItemsFromAllDrives=True,supportsAllDrives=True).execute()
files = response.get('files')
nextPageToken = response.get('nextPageToken')
while nextPageToken:
response = drive.files().list(q=query,includeItemsFromAllDrives=True,supportsAllDrives=True).execute()
files.extend(response.get('files'))
nextPageToken = response.get('nextPageToken')
df = pd.DataFrame(files)
你的问题是你打电话给父母的方式
query = f"parents = '{folderId}'"
父母=应该是父母
query = f"parents in '{folderId}'"
当您使用 Q 参数时,从简单开始。 你能通过搜索 mimetype 找到文件夹吗?
page_token = None
while True:
response = drive_service.files().list(q="mimeType='application/vnd.google-apps.folder'",
fields='nextPageToken, files(id, name)',
pageToken=page_token).execute()
for file in response.get('files', []):
# Process change
print 'Found file: %s (%s)' % (file.get('name'), file.get('id'))
page_token = response.get('nextPageToken', None)
if page_token is None:
break
假设您在上一次通话中取回文件夹,您需要获取该通话的文件 ID 并将其发送到此次通话。
page_token = None
while True:
response = drive_service.files().list(q="parents in 'FILEIDFROMPREVIOUSCALL'",
fields='nextPageToken, files(id, name)',
pageToken=page_token).execute()
for file in response.get('files', []):
# Process change
print 'Found file: %s (%s)' % (file.get('name'), file.get('id'))
page_token = response.get('nextPageToken', None)
if page_token is None:
break
我试图在 Python 中使用 Google Drive API 获取文件夹列表。 我可以在我的驱动器文件夹中获取列表,但我无法获取共享文件夹的项目列表。 我使用 GCP 服务帐户作为凭据,并且我已经将服务帐户设置到共享文件夹中。 谁有解决方案?? 我应该使用另一个参数吗? 太感谢了。
drive = build('drive', 'v3', credentials=credentials)
folderId = "xxxxxxxxxxx"
query = f"parents = '{folderId}'"
response = drive.files().list(q=query,includeItemsFromAllDrives=True,supportsAllDrives=True).execute()
files = response.get('files')
nextPageToken = response.get('nextPageToken')
while nextPageToken:
response = drive.files().list(q=query,includeItemsFromAllDrives=True,supportsAllDrives=True).execute()
files.extend(response.get('files'))
nextPageToken = response.get('nextPageToken')
df = pd.DataFrame(files)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.