我有一个文件夹路径,例如/docs/word,我想获取“word”文件夹(最后一个文件夹)的 ID,以便在那里上传文件。如何获取 ID?
最佳答案
所以我想通了。你要做的就是获取root的id drive_service.about().get().execute()["rootFolderId"]
,然后获取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
关于python - Google 云端硬盘文件夹 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15278315/