如何使用 PyDrive 访问团队云端硬盘而不是个人 Google 云端硬盘? [英] How can I access a Team Drive instead of personal Google Drive using PyDrive?

查看:33
本文介绍了如何使用 PyDrive 访问团队云端硬盘而不是个人 Google 云端硬盘?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 PyDrive 以编程方式列出并下载存储在团队云端硬盘上的文件,我可以在浏览器中访问这些文件.当我这样做时:

I am trying to use PyDrive to programmatically list and then download files stored on a Team Drive that I can access in a browser. When I do this:

from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive

gauth = GoogleAuth()
drive = GoogleDrive(gauth)

file_list = drive.ListFile(
    {
        'q': "'root' in parents and trashed=false",
        'corpora': "teamDrive",
        'teamDriveId': <team drive ID>,
        'includeTeamDriveItems': "true",
        'supportsTeamDrives': "true"
    }
).GetList()
for file1 in file_list:
    print('title: %s, id: %s' % (file1['title'], file1['id']))

我只获得我的个人驱动器上的文件列表,而不是团队驱动器上的文件列表.我做错了什么?

I only get the list of files on my personal drive, not the team drive. What am I doing wrong?

注意 1:我通过在浏览器中打开 Team Drive(根文件夹)并复制 "https://drive.google.com/drive/folders/"

Note1: I got the <team drive ID> by opening the Team Drive (the root folder) in the browser and copying everything after "https://drive.google.com/drive/folders/"

注意2:浏览器在drive.ListFile处弹出,提示Authentication成功.

推荐答案

在团队驱动器中,文件只能有一个父文件夹,并且团队驱动器文件的父级永远不是根目录.

In a team drive, files can only have one parent folder and a team drive file's parent is never root.

我能够再次使用驱动器 ID 而不是 root 来让它工作,但我也使用布尔值来代替字符串:

I was able to use the drive id again instead of root to get this to work, but I also used boolean values for true instead of strings:

drive.ListFile({'q':"'<Team_Drive_Id_Or_Folder_Id>' in parents and trashed=false", 'corpora': 'teamDrive', 'teamDriveId': '<Team_Drive_Id>', 'includeTeamDriveItems': True, 'supportsTeamDrives': True}).GetList()

这篇关于如何使用 PyDrive 访问团队云端硬盘而不是个人 Google 云端硬盘?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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