如何使用PyDrive访问Team Drive而不是个人Google Drive? [英] How can I access a Team Drive instead of personal Google Drive using PyDrive?
问题描述
我正在尝试使用PyDrive以编程方式列出然后下载存储在Team Drive中的文件,这些文件可以在浏览器中访问.当我这样做时:
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(根文件夹)并复制"<team drive ID>/drive/folders/"rel =" nofollow noreferrer> 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 successful.
Note2: Browser pops up at drive.ListFile
and gives Authentication successful.
推荐答案
在团队驱动器中,文件只能有一个父文件夹,而团队驱动器文件的父文件夹永远不会是根文件.
In a team drive, files can only have one parent folder and a team drive file's parent is never root.
我能够再次使用驱动器ID而不是root来使它工作,但是我也使用布尔值表示true而不是字符串:
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访问Team Drive而不是个人Google Drive?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!