Google apps script GMail插件:过期的访问令牌
我的gmail插件由几张卡组成。对于卡片导航,我广泛使用setOnClickAction,例如Google apps script GMail插件:过期的访问令牌,google-apps-script,gmail-addons,Google Apps Script,Gmail Addons,我的gmail插件由几张卡组成。对于卡片导航,我广泛使用setOnClickAction,例如 CardService.newAction().setFunctionName('openUserCard').setParameters({userJSON: JSON.stringify(user)}) Gmail插件引用的setParameters方法的键和值必须是字符串。这就是为什么不可能将任何复杂对象从一张卡发送到另一张卡的原因 全局变量也不受支持。可以使用PropertiesServic
CardService.newAction().setFunctionName('openUserCard').setParameters({userJSON: JSON.stringify(user)})
Gmail插件引用的setParameters
方法的键和值必须是字符串。这就是为什么不可能将任何复杂对象从一张卡发送到另一张卡的原因
全局变量也不受支持。可以使用PropertiesService
存储一些数据,但也仅限于字符串
我有信用卡和出口信用卡。在初始卡上,当前的电子邮件数据导入器如下所示:
function buildAddon(e) {
var accessToken = e.messageMetadata.accessToken;
GmailApp.setCurrentMessageAccessToken(accessToken);
var message = GmailApp.getMessageById(e.messageMetadata.messageId);
var attachments = message.getAttachments();
... we can do anything with attachments here...
问题是,我必须在另一张导出卡上使用附件,而不是在首字母上,将它们发布到某个外部api。但是我不能使用setOnClickAction
直接发送附件
数组,因为它由具有方法的复杂对象组成
这就是为什么我将初始的e.messageMetadata
对象发送到导出卡,然后重复上面的所有操作:setCurrentMessageAccessToken
,getMessageById
,getAttachments
,然后通过attachment.getBytes()
获取每个附件的内容并发送到外部api
如果客户立即使用出口卡,这一切都会起作用。但是,如果他浏览其他一些卡片几分钟,然后去导出,调用GmailApp.getMessageById(messageMetadata.messageId)
会返回一个错误Access Denied::Expired Access token
如何避免这种情况?每个操作只接收一个参数,即参数“e”事件 然后,如果我们检查该“e”,我们将找到一个带有属性参数的JSON对象,这是通过操作的setParameters()方法发送到操作函数的参数 在这个变量“e”中还有一个名为messageMetadata的属性,它具有所有正确的值
var myAction = CardService.newAction().setFunctionName("xpto").setParameters({ name: "banana"} );
function xpto(e) {
var name = e.parameters.name;
}
示例“e”事件中包含以下JSON:
{
formInput = {},
clientPlatform = web,
messageMetadata = {
messageId= ... ,
accessToken= ...
},
formInputs = {},
parameters = { name=Banana }
}
希望这仍然有用。非常感谢!测试花了一些时间,但似乎我们还没有过期代币问题了。