我可以通过以下方式与给定用户共享文件:
user_permission = ({
'type': 'user',
'role': 'writer',
'emailAddress': "example@gmail.com",
})
service.permissions().create(fileId=fileId,body=user_permission,fields='id').execute()
但是,我不知道如何与多个用户共享该文件。
我已经阅读了中的文档https://developers.google.com/drive/api/v3/reference/permissions/create,并且我理解对于不仅仅是用户来说;类型";正文中指定的密钥必须是";组";而不是";用户";,但我在任何地方都找不到参数";emailAddress";在这种情况下应该是这样。我已经用一个邮件字符串列表证明了这一点,一个用逗号或空格分隔的邮件字符串,但这给了我以下错误:
googleapiclient.errors.HttpError: <HttpError 400 when requesting https://www.googleapis.com/drive/v3/files/1shxOQlNPqbXT-LwKTDvuwK0m-7IK43cDAWwxmnLgLvQ/permissions?fields=id&emailMessage=This+is+a+test&alt=json returned "The specified emailAddress is invalid or not applicable for the given permission type.". Details: "[{'domain': 'global', 'reason': 'invalid', 'message': 'The specified emailAddress is invalid or not applicable for the given permission type.', 'locationType': 'other', 'location': 'permission.emailAddress'}]">
问题:
权限类型group
不指不同用户的任何组合。它指的是谷歌集团。
解决方案:
如果要与多个用户共享一个文件(这些用户不是一个完整的domain
(,则应创建一个组,将所有这些用户作为成员。
如果您有工作区帐户,则可以使用目录API以编程方式管理组(请参阅目录API:组和目录API:组成员(。
在这种情况下,来自请求主体的emailAddress
将发送组电子邮件:
如果
type
是user
或group
,则必须为用户或组提供emailAddress
否则,唯一的选择是与不同的用户单独共享文件,就像您当前所做的那样。
参考:
- 权限类型