【发布时间】:2021-06-12 20:54:40
【问题描述】:
我可以通过以下方式与给定用户共享文件:
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'}]">
【问题讨论】:
-
如果您想与一组用户共享(这组用户不是整个域),您应该 create a group 与所有这些用户作为成员(这里是如何 manage a group programmatically 和这里如何到manage its members)。然后,
emailAddress将是组电子邮件。如果您不这样做,则必须分别为每个用户授予权限。 -
感谢@lamblichus 的评论,我不知道 Google 群组的概念。