【问题标题】:How can I access a Team Drive instead of personal Google Drive using PyDrive?如何使用 PyDrive 访问团队云端硬盘而不是个人 Google 云端硬盘?
【发布时间】:2019-04-17 14:28:06
【问题描述】:

我正在尝试使用 PyDrive 以编程方式列出并下载存储在团队云端硬盘上的文件,我可以在浏览器中访问这些文件。当我这样做时:

from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive

gauth = GoogleAuth()
drive = GoogleDrive(gauth)

file_list = drive.ListFile(
    {
        'q': "'root' in parents and trashed=false",
        'corpora': "teamDrive",
        'teamDriveId': <team drive ID>,
        'includeTeamDriveItems': "true",
        'supportsTeamDrives': "true"
    }
).GetList()
for file1 in file_list:
    print('title: %s, id: %s' % (file1['title'], file1['id']))

我只获得我的个人驱动器上的文件列表,而不是团队驱动器上的文件列表。我做错了什么?

注意1:我通过在浏览器中打开团队驱动器(根文件夹)并复制“https://drive.google.com/drive/folders/”之后的所有内容来获得&lt;team drive ID&gt;

注意2:浏览器在drive.ListFile弹出并给出Authentication successful.

【问题讨论】:

    标签: google-drive-api google-drive-shared-drive pydrive


    【解决方案1】:

    在团队驱动器中,文件只能有一个父文件夹,并且团队驱动器文件的父级永远不是根目录。

    我能够再次使用驱动器 ID 而不是 root 来让它工作,但我也使用布尔值代替字符串:

    drive.ListFile({'q':"'<Team_Drive_Id_Or_Folder_Id>' in parents and trashed=false", 'corpora': 'teamDrive', 'teamDriveId': '<Team_Drive_Id>', 'includeTeamDriveItems': True, 'supportsTeamDrives': True}).GetList()
    

    【讨论】:

    • 感谢工作。现在我需要弄清楚如何下载这些文件。似乎无法使用团队驱动器文件,只能使用我驱动器中的文件...
    • 谢谢!即使更新了共享驱动器,这也对我有用。
    猜你喜欢
    • 2017-09-21
    • 1970-01-01
    • 1970-01-01
    • 2019-02-28
    • 1970-01-01
    • 2012-07-12
    • 2018-10-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多