如何在通过 Google Apps 脚本将查看器添加到 Google 电子表格时发送自定义消息?

How to send a custom message when adding a viewer to Google Spreadsheet via Google Apps Scripts?

我正在尝试通过 Google Apps 脚本将查看器添加到 Google 电子表格,并且在这样做的同时,还会发送一条自定义消息,例如 "Hi there! I'm sending this to you becase X, Y and Z"。

我已经在 此处看到与添加编辑器时使电子邮件静音相关的 SO,但我不知道如何修改它以便发送自定义消息。

我在尝试什么:

Drive.Permissions.insert({'value': "my@email.com",
                        'type': "user",
                        'role': "reader",
                        'emailMessage': "Random text"
                        },
                       'mySpreadsheetKey');
}

我希望 "emailMessage" 能够实现该目的,如 Drive API docs 中所述。但是,考虑到参数,我可以看到该参数没有包含在请求正文中,而是包含在参数列表中,所以我不确定该怎么做。

就在我完成 post 的时候,我想通了。原来,在Advanced Drive Service docs的最后一节中没有指定,但是,显然,请求参数应该作为第三个参数发送,而不是在请求体内发送。所以,我的代码原来是:

Drive.Permissions.insert({'value': "my@email.com",
                        'type': "user",
                        'role': "reader"
                        },
                       'mySpreadsheetKey',
                       {'emailMessage': "Random text"});

考虑到我找不到类似的 post。

,我决定留下这个问题,这样它可以帮助其他人