使用pydrive将文件上载到共享Google驱动器中的共享文件夹时,“不允许使用方法”

2024-10-01 07:26:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我在共享的谷歌硬盘中有一个共享文件夹

https://gyazo.com/ae22a1d04eeddf9de49adbf470706ac8

我正在尝试使用Pydrive将一个文件上载到这个团队的google drive。此代码用于上传到我的驱动器中的特定文件夹,但不在共享驱动器中的任何文件夹中

    file_drive = drive.CreateFile({'title': file_name,
                      "parents": [{"kind": "drive#fileLink", "id": folder_id}]})
    file_drive.SetContentFile(f.name)
    file_drive.Upload()

我拥有对所有文件的完全访问权限以及创建/删除文件/文件夹的权限。谁能给我一个提示吗


Tags: 文件namehttps文件夹comid权限drive
1条回答
网友
1楼 · 发布于 2024-10-01 07:26:28

当我写这篇文章的时候,我偶然发现了以下线索

https://github.com/gsuitedevs/PyDrive/issues/149

使用以下代码并使用“supportsTeamDrives”和“teamDriveId”参数可以轻松解决此问题

    file_drive = drive.CreateFile({
        'title': fn,
        'parents': [{
            'kind': 'drive#fileLink',
            'teamDriveId': team_drive_id,
            'id': folder_id
        }]
    })
    file_drive.SetContentFile(f.name)
    file_drive.Upload(param={'supportsTeamDrives': True})

相关问题 更多 >