PyDrive 中带有 InsertPermission() 的可选查询参数

Optional query parameters with InsertPermission() in PyDrive

是否可以在 PyDrive 中使用 InsertPermission() 发送可选查询参数的值? PyDrive 文档似乎忽略了如何处理切换可选参数,例如 sendNotificationEmails.

我需要为特定用户而不是任何人添加对文件的权限,而不发送通知电子邮件,并且 sendNotificationEmails 默认设置为 True

我考虑过将 files.py 的函数定义修改为以下内容,但我不确定这是否可行,而且我之前没有编辑过库:

def InsertPermission(self, new_permission):
  """Insert a new permission. Re-fetches all permissions after call.

  :param new_permission: The new permission to insert, please see the official Google Drive API guide on permissions.insert for details.

  :type new_permission: object

  :return: The permission object.
  :rtype: object
  """
  file_id = self.metadata.get('id') or self['id']
  try:
    permission = self.auth.service.permissions().insert( fileId=file_id, body=new_permission, sendNotificationEmails=False).execute(http=self.http)
  except errors.HttpError as error:
    raise ApiRequestError(error)
  else:
    self.GetPermissions()  # Update permissions field.

  return permission

现在可以指定可选参数作为 InsertPermission() 函数的附加参数,如下所示:

file1.InsertPermission({'type': 'user',
                        'value': 'insert@email.here',
                        'role': 'reader'}, sendNotificationEmails=False)

请参阅官方文档here了解所有可用参数。

注意:您目前(2017 年 4 月)需要为此功能安装库的开发版本。这个版本的 PyDrive 可以像这样安装:

pip install git+https://github.com/googledrive/PyDrive.git@development#egg=PyDrive