我已经成功地用PyDrive将文件上传到google驱动器文件夹中。但是,当要将文件上传到与我共享的googledrive 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})
我收到的错误消息是: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">
'0AG-N4DqGC1nbUk9PVA'是teamdrive的文件夹id。在
我一直在寻找用PyDrive上传文件到Teamdrives的方法,但是没有成功。我在pydrive的github页面上看到,他们在大约8个月前添加了teamdrives支持。但是我找不到任何关于如何使用它的文档。谁能告诉我哪里错了吗?在
要上载,请尝试制作一个名为“的文件”设置.yaml“并按照以下说明将其保存在您的工作目录中: https://pythonhosted.org/PyDrive/oauth.html
您需要在客户端中找到的客户端id和客户端密码_机密.json在你授权访问googleapi之后,这个文件也应该在你的目录中。在
使用以下代码进行测试,在team drive中的文件夹中生成一个文本文件:
相关问题 更多 >
编程相关推荐