如何从团队驱动器下载文件?

How can I download files from team drives?

我想定期从 google 驱动器上的共享团队驱动器下载和上传文件。我可以上传到文件夹,但不能下载。

这是我试过的

team_drive_id = 'YYY'
file_to_download= 'ZZZ'
parent_folder_id = 'XXX'

f = drive.CreateFile({
        'id':file_to_download,
        'parents': [{
        'kind': 'drive#fileLink',
        'teamDriveId': team_folder_id,
        'id': parent_drive_id
    }]
})
f= drive.CreateFile({'id': file_to_download})
f.GetContentFile('test.csv', mimetype='text/csv')

但这就是我得到的:

ApiRequestError: <HttpError 404 when requesting https://www.googleapis.com/drive/v2/files/file_to_download?alt=json returned "File not found: file_to_download">

有什么建议吗?

按照可以看到的文档here

首先创建文件:

f = drive.CreateFile({'id': file_to_download})

然后你在文件上设置内容

f.SetContentString("whatever comes inside this file, it is a csv so you know what to expect to be here")

并完成您需要做的上传

f.Upload()

之后,文件在那里正确创建,您可以使用GetContentString方法读取它