打开卡时在 gmail 插件上发出 http 请求

Make http request on gmail addon when card is opened

我正在用 appscript 编写一个 gmail 插件,我希望它仅在用户打开插件时执行 http 请求,而不是每次呈现卡片时。

function main(e){
   var mainCard = CardService.newCardBuilder();
   // Set up card sections
   UrlFetchApp.fetch(...) // Will perform the request even if addon is not opened
   return [card.build()]
}

是否可以在卡打开而不是渲染时执行 UrlFetchApp?

根据 Gmail 插件中的 documentation, you cannot create or use Apps Script simple nor installable triggers

但是,您可以尝试查看 time-driven triggers 作为解决方法。

Time-driven triggers

A time-driven trigger (also called a clock trigger) is similar to a cron job in Unix. Time-driven triggers let scripts execute at a particular time or on a recurring interval, as frequently as every minute or as infrequently as once per month. (Note that an add-on can use a time-driven trigger once per hour at most.)

您也可以参考此了解其用法。