我有一个文件夹路径,例如/docs/word,我想获取“word”文件夹(最后一个文件夹)的ID,以便在那里上传文件。我如何获取身份证?
所以我想通了。你要做的就是获取 root 的 iddrive_service.about().get().execute()["rootFolderId"]
,然后获取根目录中的文件,转到路径中的下一个文件夹等。顺便说一句,我编写的函数用于列出路径中的文件夹并将它们保存到字典中(使用 self.addPath() )
def listFolders(self, path):
fId = self.getPathId(path) #get the id of the parent folder
files = self.drive_service.children().list(folderId=fId).execute() #Request children
files = files["items"] #All of the items in the folder
folders = []
for i in range(len(files)):
sId = files[i]["id"]
sFile = self.drive_service.files().get(fileId=sId).execute()
if sFile["labels"]["trashed"] == False and sFile["mimeType"] == "application/vnd.google-apps.folder":
self.addPath(path+sFile["title"]+"/", sFile["id"])
folders.append(sFile["title"])
return folders
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)