簡體   English   中英

使用 PyDrive 列出共享的 Google Team Drive 文件夾中的所有文件

[英]List all files in folder in shared Google Team Drive using PyDrive

我正在嘗試使用 PyDrive 獲取 Google Drive 文件夾中所有文件 ID 的列表。 當我在我的驅動器中的文件夾上使用它時,我的查詢有效,但當我嘗試在共享的 Google 團隊驅動器中的文件夾上使用它時它不起作用。

file_list = drive.ListFile({'q': "'folder_id_goes_here' in parents"}).GetList()

我嘗試附加 arguments 像 'team_drive_id' = team_drive_id_goes_here 和 'supports_team_drive' = True,但我不確定我是否正確添加了這些。

team_drive_id = 'team_drive_id_goes_here'

file_list = drive.ListFile({
     'q': "'folder_id_goes_here' in parents",
     'supportsTeamDrives': True,
     'teamDriveId' = team_drive_id
}).GetList()

當我將這些 arguments 添加到 ListFile function 時,我最終得到一個 'googleapiclient.errors.HttpError: <HttpError 403' 錯誤。

有誰知道如何修改此查詢以使用共享團隊驅動器中的文件夾?

我想提出以下修改。

從:

team_drive_id = 'team_drive_id_goes_here'
file_list = drive.ListFile({
     'q': "'folder_id_goes_here' in parents",
     'supportsTeamDrives': True,
     'teamDriveId' = team_drive_id
}).GetList()

至:

team_drive_id = 'team_drive_id_goes_here'
file_list = drive.ListFile({
    'q': "'folder_id_goes_here' in parents",
    'supportsAllDrives': True,  # Modified
    'driveId': team_drive_id,  # Modified
    'includeItemsFromAllDrives': True,  # Added
    'corpora': 'drive'  # Added
}).GetList()

或者

file_list = drive.ListFile({
    'q': "'folder_id_goes_here' in parents",
    'supportsAllDrives': True,  # Modified
    'includeItemsFromAllDrives': True,  # Added
}).GetList()

筆記:

  • 官方文檔Warning: This item is deprecated. 對於includeTeamDriveItemsteamDriveId 所以在這種情況下,請分別使用includeItemsFromAllDrivesdriveId

參考:

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM