在 Apps Script 中,我目前正在以編程方式生成檔案,通過添加用戶addEditor()并自動向他們發送電子郵件。
我現在想做的是擴展它以包含一條訊息。我認為這與這個綠色框相對應:

我在這里也發現了一個類似的問題,但無法使其正常作業:如何通過 Google Apps 腳本將查看器添加到 Google 電子表格時發送自定義訊息?
這是我到目前為止所擁有的:
setPermission(documentId, email) {
// Get the document to set permissions on
const file = DriveApp.getFileById(documentId);
// Turn off sharing by editors
file.setShareableByEditors(false);
// Add the email to editors
file.addEditor(email);
}
如果我嘗試做類似的事情:
...
file.addEditor(email, {emailMessage: 'Test'});
我收到以下錯誤:
Exception: The parameters (String,(class)) don't match the method signature for DriveApp.File.addEditor.
所以我很好奇:
- 這是可行的嗎?
- 語法需要是什么?
uj5u.com熱心網友回復:
如檔案所述,file.addEditor()只有一個引數:電子郵件地址(或用戶物件)。因此無法通過該方法添加電子郵件。
但是,您可以使用Advanced Drive Service完成此操作。首先,您需要啟用高級驅動器服務。
然后使用這樣的東西(參考):
Drive.Permissions.insert(
{
'role': 'writer,
'type': 'user',
'value': email // the email address you wish to share with
},
documentId, // id of the file you want to share
{
'sendNotificationEmails': 'true',
'emailMessage': message // The message you want to send, as a plain text string
});
uj5u.com熱心網友回復:
我在這里發現了一個類似的問題,我測驗了建議的語法并且它有效,所以是的,這是可行的。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/416099.html
標籤:
