【发布时间】:2019-03-01 22:15:59
【问题描述】:
我正在使用以下范围运行我的 gmail 插件:
https://mail.google.com/
https://www.googleapis.com/auth/gmail.addons.execute
https://www.googleapis.com/auth/gmail.addons.current.action.compose
https://www.googleapis.com/auth/gmail.addons.current.message.metadata
https://www.googleapis.com/auth/script.external_request
我有一个按钮和相应的撰写操作事件,它应该从某些输入字段中读取收件人、主题和正文信息,并将这些信息插入到撰写 UI 中。
撰写操作回调如下所示:
function autofillEmailDraft(e) {
var recipient = e.formInput.recipient;
var subject = e.formInput.subject;
var body = e.formInput.body;
GmailApp.setCurrentMessageAccessToken(e.messageMetadata.accessToken);
var draft = GmailApp.createDraft(recipient, subject, body);
// Return a built draft response. This causes Gmail to present a
// compose window to the user, pre-filled with the content specified
// above.
return CardService.newComposeActionResponseBuilder()
.setGmailDraft(draft).build();
}
单击按钮时,插件崩溃并显示以下错误消息:TypeError: Cannot read property "accessToken" from undefined.
e.messageMetadata 似乎未定义。我应该在其他地方寻找访问令牌吗?
只需删除违规行
GmailApp.setCurrentMessageAccessToken(e.messageMetadata.accessToken);
不起作用。加载项因不同的错误而崩溃
Access denied: : Missing access token for authorization. Request: MailboxService.CreateDraft.
cmets 后更新:
这是触发撰写操作的按钮小部件的代码:
var submitButton = CardService.newTextButton()
.setTextButtonStyle(CardService.TextButtonStyle.FILLED)
.setText('Yes')
.setComposeAction(
CardService.newAction().setFunctionName('autofillEmailDraft'),
CardService.ComposedEmailType.STANDALONE_DRAFT
);
这是记录的“e”对象:
{
formInput={body=Hello},
parameters={},
draftMetadata={
toRecipients=[abcd@example.com],
bccRecipients=[],
ccRecipients=[]
}
}
【问题讨论】:
-
e必须是Action对象。这个函数是怎么触发的?您可以尝试Logger.log(e)了解正在传递的内容。 -
补充一下,你的动作创建脚本是什么样的(
CardService.newAction()东西)?尤其是setComposeAction()区域。 -
非常感谢您调查此事,Dustin 和 Chris。我已使用您要求的详细信息更新了问题
-
经过大量搜索后,我在 gmail 插件问题跟踪器中遇到了这个未解决的问题 [issuetracker.google.com/issues/119968497],这让我想到从扩展撰写的插件更新草稿电子邮件的收件人和主题字段尚不支持用户界面
标签: google-apps-script gmail-addons