我已成功使用PyDrive将文件上传到google-drive-folder。但是,当涉及到将文件上传到与我共享的google-drive-teamdrive文件夹中的文件夹时,以下代码无效。
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
gauth = GoogleAuth()
gauth.LocalWebserverAuth()
drive = GoogleDrive(gauth)
location_to_save = "D:\images"
mImageLoc = location_to_save + "\\abcd.jpg"
#[...Code to fetch and save the file as abcd.jpg ...]
gfolder_id = "1H1gjBKcpiHJtnXKVxWQEC1CS8t4Gswjj" #This is a google drive folder id. I am replacing this with a teamdrive folder id, but that does not work
gfile_title = mImageLoc.split("\\")[-1] # returns abcd.jpg
http = gdrive.auth.Get_Http_Object()
f = gdrive.CreateFile({"parents": [{"kind": "drive#fileLink", "id": gfolder_id}],
'title': gfile_title})
f.SetContentFile(mImageLoc)
f.Upload(param={"http": http})
我收到的错误消息是:qazxsw poi'0AG-N4DqGC1nbUk9PVA'是此处的团队驱动器文件夹ID。
我一直在寻找使用PyDrive上传文件到Teamdrives的方法但是徒劳无功。我在pydrive的github页面中看到他们在大约8个月前添加了teamdrives支持。但我找不到任何关于如何使用它的文档。任何人都可以建议我在哪里错了吗?
要上传,请按照以下说明尝试制作一个名为“settings.yaml”的文件并将其保存在工作目录中:pydrive.files.ApiRequestError: <HttpError 404 when requesting https://www.googleapis.com/upload/drive/v2/files?alt=json&uploadType=resumable returned "File not found: 0AG-N4DqGC1nbUk9PVA">
您将需要client_secrets.json文件中的客户端ID和客户端密钥,该文件在您授权访问Google API后也应该位于您的目录中。
使用以下代码对其进行测试,以在团队驱动器的文件夹中创建文本文件:
https://pythonhosted.org/PyDrive/oauth.html