我有一个文件夹路径,例如/ docs / word,我想获取“word”文件夹(最后一个文件夹)的ID,以便在那里上传文件。我如何获得身份证?
答案 0 :(得分:2)
所以我明白了。你需要做的是获取根drive_service.about().get().execute()["rootFolderId"]
的id,然后获取root文件,转到路径中的下一个文件夹等等。顺便说一句,我编写的函数列出路径中的文件夹并将它们保存到字典中(使用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