guy*_*zyl 5 python python-2.7 google-drive-api
我有一个文件夹路径,例如 /docs/word,我想获取“word”文件夹(最后一个文件夹)的 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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5558 次 |
| 最近记录: |