使用Python将成员添加到Google Drive共享驱动器

时间:2020-10-05 09:40:16

标签: python google-drive-api google-colaboratory drive

如何将成员添加到Google云端硬盘的共享云端硬盘?

我正在研究Colab,并尝试进行搜索,但没有发现有用的信息。

我尝试使用PyDrive,但是:

  • 我无法选择整个共享驱动器,只能选择一个文件夹

  • 即使我无法通过Google云端硬盘网络GUI进行操作,我也无法更新该文件夹的权限

这就是我现在正在做的(错误400):

from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
from google.colab import auth
from oauth2client.client import GoogleCredentials
from google.colab import drive as drv
drv.mount('/gdrive', force_remount=True)
auth.authenticate_user()
gauth = GoogleAuth()
gauth.credentials = GoogleCredentials.get_application_default()
drive = GoogleDrive(gauth)

%cd /gdrive/Shared\ drives/

file_list = drive.ListFile({'q': "  title = 'FolderTitleOrSharedDriveTitle'"}).GetList()
for file1 in file_list:
  print('title: %s, id: %s' % (file1['title'], file1['id']))
  file = file1
print(file['title'])
file.GetPermissions()

new_permission = {
    'type': 'user',
    'value': 'usertogrant@access.com',
    'role': 'reader'
}
permission = file.auth.service.permissions().insert(fileId=file['id'], body=new_permission, supportsAllDrives=True).execute(http=file.http)

0 个答案:

没有答案