Google云端硬盘文件夹ID [英] Google Drive folder ID

查看:484
本文介绍了Google云端硬盘文件夹ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文件夹路径,例如/ docs / word,我想获得word文件夹(最后一个文件夹)的ID,以便在那里上传文件。如何获得ID?

I have a folder path, for example /docs/word, and I would like to get the ID of the "word" folder (the last folder), in order to upload a file there. How do I get the ID?

推荐答案

所以我想通了。你需要做的是获取根 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

这篇关于Google云端硬盘文件夹ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆