0

是否可以在PyDrive中使用InsertPermission()發送可選查詢參數的值? PyDrive文檔似乎忽略瞭如何處理切換可選參數,如sendNotificationEmailsPyDrive中帶有InsertPermission()的可選查詢參數

我需要爲特定用戶(而不是任何人)添加權限,而不發送通知電子郵件,並且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 
+0

不要修改庫的代碼。向PyDrive維護人員發送功能請求,並且直到它實現了您自己項目中修改過的代碼的副本。 –

+0

PyDrive維護者在這裏,打開一個錯誤在這裏:https://github.com/googledrive/PyDrive/issues。您可以分叉庫並進行更改。如果他們工作,我很樂意將他們合併到主庫中。 –

回答

1

指定可選參數現在可以作爲額外的參數給InsertPermission()功能,像這樣:

file1.InsertPermission({'type': 'user', 
         'value': '[email protected]', 
         'role': 'reader'}, sendNotificationEmails=False) 

請參閱官方文檔here可用的所有參數。

注意:您目前(2017年4月)需要安裝此功能庫的開發版本。這個版本的PyDrive可以這樣安裝:

pip install git+https://github.com/googledrive/[email protected]#egg=PyDrive