【问题标题】:Optional query parameters with InsertPermission() in PyDrivePyDrive 中带有 InsertPermission() 的可选查询参数
【发布时间】:2017-04-16 13:32:20
【问题描述】:

是否可以在 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

【问题讨论】:

  • 不要修改库的代码。向 PyDrive 维护者发送一个功能请求,在它实现之前,在您自己的项目中拥有修改后的代码的副本。
  • PyDrive 维护者在这里,在这里打开一个错误:github.com/googledrive/PyDrive/issues。您可以分叉库并进行更改。如果它们有效,我很乐意将它们合并到主库中。

标签: python google-api google-drive-api google-api-python-client pydrive


【解决方案1】:

现在可以指定可选参数作为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

【讨论】:

  • 直接用于google api(V3),为sendNotificationEmail,单数
猜你喜欢
  • 2017-11-29
  • 2014-10-05
  • 2021-07-15
  • 1970-01-01
  • 1970-01-01
  • 2020-10-15
  • 2011-01-27
  • 2018-08-16
  • 2018-01-04
相关资源
最近更新 更多