我将用一个例子来展示我的问题:
我有一个按钮.单击时,它会根据TextInputFields加载项中的内容创建邮件草稿.我有一个验证功能,可以说明字段填写是否正确.
如果我想以某种方式通知用户有关错误的字段,我必须创建一个通知或重建带有错误信息的卡.这些操作可以正常返回Action,但不能返回composeAction(因为composeAction必须使用构建的草稿返回),所以我必须向composeAction按钮注册一个简单的操作.
当我点击这种按钮时,只有一个动作执行而另一个动作无效.
关于我如何尝试实现的一些代码:
section.addWidget(CardService.newTextButton()
.setText('Validate and Create')
.setComposeAction(CardService.newAction().setFunction('doIt'), CardService.ComposedEmailType.STANDALONE_DRAFT)
.setOnClickAction(CardService.newAction().setFunction('notify')));
Run Code Online (Sandbox Code Playgroud)
ActionFunctions:
function doIt(event){
validate the event['formInput'] object;
if(valid the formInput)
create andr return the draft;
else
return null;
}
function notify(event){
validate the event['formInput'] object;
if(valid the formInput)
return null;
else
return notify or rebuilded card with error info;
}
Run Code Online (Sandbox Code Playgroud)
主要是简单的动作运行,而compose什么都不做.如果我将Logger.log()函数放在回调函数中,则只有一个出现在api日志中.
有人在验证之前尝试过并在同一次点击中创建草稿吗?
我创建了简单的Gmail插件,现在我正在努力应对以下策略.
安装插件后,当第一个收件箱打开时,我们会询问用户输入的基本信息,当他打开第二封邮件时,我们不会再次询问基本信息详情.
我怎么能处理这个?
我尝试过物业服务,但没有运气.
更新
var MAX_THREADS = 5;
/**
* Returns the array of cards that should be rendered for the current
* e-mail thread. The name of this function is specified in the
* manifest 'onTriggerFunction' field, indicating that this function
* runs every time the add-on is started.
*
* @param {Object} e data provided by the Gmail UI.
* @returns {Card[]}
*/
function buildAddOn(e) {
// Activate temporary Gmail add-on scopes.
//Logger.log('E', Session.getActiveUser());
var accessToken = …Run Code Online (Sandbox Code Playgroud) persistence global-variables google-apps-script gmail-addons
我正在使用Google Apps脚本创建Gmail插件的背景.通过这个插件,我想使用REST服务请求连接到我的后端服务器(非Google服务).该请求必须经过授权.授权后,我可以向该服务器发出请求,以接收与该数据库中该用户相关的数据.我已经在我的webapp中使用Google登录来登录后端服务 - 在前端,我在授权响应中收到了GoogleUser对象内部的id_token.
问题是
我需要这个id_token才能通过Gmail插件连接到我的后端服务.但是,我找不到如何访问令牌的方法.
我认为必须通过Apps脚本中的API提供令牌
的研究
.
在webapp中,我使用Google Auth API收到id_token,如下所示:
Promise.resolve(this.auth2.signIn())
.then((googleUser) => {
let user_token = googleUser.getAuthResponse().id_token; // this is the id_token I need in the Gmail plugin, too
// send the id_token to the backend service
...
};
Run Code Online (Sandbox Code Playgroud)
在Google Apps脚本API中,我只能找到OAuth令牌:
ScriptApp.getOAuthToken();
Run Code Online (Sandbox Code Playgroud)
我假设令牌也可以存储在会话中.Google Apps脚本API包含Session类,它本身包含getActiveUser方法,该方法返回User对象.但是,User对象仅包含用户的电子邮件地址,没有id令牌(或其他任何内容):
Session.getActiveUser().getEmail();
Run Code Online (Sandbox Code Playgroud)
问题
是否有办法获取身份令牌?
我是否选择使用Gmail中已登录用户的数据登录后端服务器的正确方法?
google-api google-openid google-apps-script google-oauth gmail-addons
在Gmail插件中的卡片/小部件中实现/显示日期选择器UI的最佳方法是什么?我的用例是显示所选日期的用户日历事件.任何帮助都提前非常感谢!
我有一个GMail AddOn,它使用OAuth2来授权外部服务.启动AddOn时,我通过调用检查用户是否已经拥有访问令牌oauthService.hasAccess().如果用户没有令牌,那么我将显示一张卡片,上面写着"您需要授权该服务".
该卡包含如下构建的链接:
section.addWidget(CardService.newTextButton()
.setText("Authorize MyService")
.setAuthorizationAction(
CardService.newAuthorizationAction()
.setAuthorizationUrl(authorizationUrl)
));
Run Code Online (Sandbox Code Playgroud)
当用户单击"授权MyService"按钮时,会出现一个弹出窗口,并且旧卡片中会出现一个微调器.然后用户登录MyService,授权访问,并AuthorizeCallback使用令牌调用我的.我存储令牌,并返回一个只关闭自己的HtmlPage.
原卡中的微调器停止旋转.但是,AddOn不会重新加载.这表明在授权完成时存在阻止AuthorizationAction卡重新加载的内容.有什么建议吗?
我希望AddOn重新加载,因为入口点函数将发现现在oauthService.hasAccess()返回true,然后将显示正常的"您被授权"卡(并开始处理电子邮件到MyService).
谢谢你的帮助!
现在,在gmail appscript中我们没有任何选项来添加密码类型字段.
用于附加组件的Gmail卡服务具有很好的显示内容的能力.我们可以与任何具有基本REST api的应用程序集成.我们需要通常需要密码类型字段的身份验证.
任何解决密码类型字段的工作?
如果Google认为该电子邮件不安全,则附加的侧边栏仅声明“此消息无法使用的内容”。
似乎没有任何清单选项可以帮助解决此问题,或者至少我找不到任何提及的地方。
有没有一种方法可以为Google认为不安全的电子邮件启用gmail插件?
我的问题与此类似:我正在构建一个 Gmail 插件,并想在我的 Android 手机的 Gmail 应用程序上测试它。此外,我还从 Google Play 商店安装了两个附加组件——Asana 和 Trello。然而,即使遵循我链接的问题中的建议,我的手机上也没有显示任何附加组件。
更多详细信息:在我桌面上的浏览器中,所有三个附加组件均显示并正常运行。然而,在我手机上的 Gmail 应用程序中,它们都没有出现。我链接的问题的答案是“打开一条消息并滚动到底部,它就会出现”,但这个建议对我不起作用。我还可以如何让附加组件显示在 Gmail 应用程序中?我使用的是最新稳定版本的 Oreo,并且使用与计算机上相同的 Google 帐户在手机上登录。
先谢谢您的帮助。
我在使用 Apps 脚本做很多场景时做噩梦,但没有任何效果!我有一个函数可以让GET请求返回一组卡片。现在,有时我需要再次刷新此卡以获取新内容。
function listTemplatesCards(){
var getAllTemplates = getTemplates();
var allTemplates = getAllTemplates.templates;
var theUserSlug = getAllTemplates.user_slug;
var templateCards = [];
//There are templates
if(allTemplates.length > 0){
allTemplates.forEach(function(template){
templateCards.push(templateCard(template, theUserSlug).build());
});
return templateCards;
}
}
Run Code Online (Sandbox Code Playgroud)
该函数在 上调用onTriggerFunction。现在,如果我移到另一张卡上,我想再次回到根目录,但以干净清晰的方式,我使用它,但它不起作用:
//Move the user to the root card again
var refreshNav = CardService.newNavigation().popToRoot();
return CardService.newActionResponseBuilder().setStateChanged(true).setNavigation(refreshNav).build();
Run Code Online (Sandbox Code Playgroud)
简单地说,我想要的是一旦用户点击Refresh按钮,卡片就会刷新/更新自己以再次调用并获取新数据。
我正在创建一个Gmail附加组件(对于新外观 Gmail - 大约在2018年5月),我看不出如何可以在侧边栏上"始终"提供加载项,例如日历/保留和任务加载项.
我只能找到允许在单击电子邮件时为其添加的文档,以便在侧栏中为该电子邮件提供一些上下文信息.
我正在开发的附加组件旨在为整个gmail收件箱提供服务,而不是对邮件具体操作.
目前是不可能还是我在清单或其他地方遗漏了什么?
