且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Google云端硬盘文件夹ID

更新时间:2023-02-14 16:02:22

所以我想通了。你需要做的是获取根 drive_service.about()。get()。execute()[rootFolderId] 的id,然后获取文件根,转到路径中的下一个文件夹等等。btw,我写的函数列出路径中的文件夹并将它们保存到字典中(使用self.addPath())

So I figured it out. What you have to do is get the id of the root drive_service.about().get().execute()["rootFolderId"] , and then get the files in root, go to the next folder in the path, etc. btw, the function i wrote to list the folders inside a path and save them to a dictionary (using 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