【发布时间】:2021-10-20 19:12:55
【问题描述】:
我正在尝试修改 cats quickstart 教程以在底部添加通知,以便在遇到任何错误时通知用户(例如 toast 通知或类似的东西)。
我有:
function createCatCard(text, isHomepage) {
if (!isHomepage) {
isHomepage = false;
}
// Use the "Cat as a service" API to get the cat image. Add a "time" URL
// parameter to act as a cache buster.
var now = new Date();
// Replace formward slashes in the text, as they break the CataaS API.
var caption = text.replace(/\//g, ' ');
var imageUrl = Utilities.formatString('https://cataas.com/cat/says/%s?time=%s', encodeURIComponent(caption), now.getTime());
var image = CardService.newImage().setImageUrl(imageUrl).setAltText('Meow')
// Create a button that changes the cat image when pressed.
// Note: Action parameter keys and values must be strings.
var action = CardService.newAction().setFunctionName('onChangeCat').setParameters({text: text, isHomepage: isHomepage.toString()});
var button = CardService.newTextButton().setText('Change cat').setOnClickAction(action).setTextButtonStyle(CardService.TextButtonStyle.FILLED);
var buttonSet = CardService.newButtonSet().addButton(button);
// Create a footer to be shown at the bottom.
var footer = CardService.newFixedFooter().setPrimaryButton(CardService.newTextButton().setText('Powered by cataas.com').setOpenLink(CardService.newOpenLink().setUrl('https://cataas.com')));
// Assemble the widgets and return the card.
var section = CardService.newCardSection().addWidget(image).addWidget(buttonSet);
var card = CardService.newCardBuilder().addSection(section).setFixedFooter(footer);
if (!isHomepage) {
// Create the header shown when the card is minimized,
// but only when this card is a contextual card. Peek headers
// are never used by non-contexual cards like homepages.
var peekHeader = CardService.newCardHeader().setTitle('Contextual Cat').setImageUrl('https://www.gstatic.com/images/icons/material/system/1x/pets_black_48dp.png').setSubtitle(text);
card.setPeekCardHeader(peekHeader)
}
var act = CardService.newActionResponseBuilder().setNotification(CardService.newNotification().setText('bob here').setType(CardService.NotificationType.INFO));
card.addCardAction(act);
return card.build();
}
(我添加的唯一部分是倒数第二行)。但是,当我运行代码时,我得到:
Cannot find method addCardAction(CardService.ActionResponseBuilder). [line: 62, function: createCatCard, file: Common]
编辑:
我也尝试过card.setNotification(CardService.newNotification().setText('bob here').setType(CardService.NotificationType.INFO));,但我得到了TypeError: Cannot find function setNotification in object CardBuilder. [line: 62, function: createCatCard, file: Common]
编辑2: 我也试过了
card.newNotification().setText('bob here').setType(CardService.NotificationType.INFO);
但我得到TypeError: Cannot find function newNotification in object CardBuilder. [line: 63, function: createCatCard, file: Common]
【问题讨论】:
-
没有得到预期回报时的状态码是什么?
标签: javascript google-apps-script google-drive-api google-workspace card