Rob*_*ert 2 google-apps-script gmail-addons
我用谷歌脚本创建了简单的gmail插件,因为我在这里很挣扎,
当我们执行某些操作时如何获取textinput值,我检查了文档,我找不到任何方法
我试过以下代码,
var card = CardService.newCardBuilder();
card.setHeader(CardService.newCardHeader().setTitle("Login Here"));
var section = CardService.newCardSection()
var cleint_id_Input = CardService.newTextInput()
.setFieldName("client_id")
.setTitle("Please enter clinet id")
var username_Input = CardService.newTextInput()
.setFieldName("username")
.setTitle("Please enter username")
var password_Input = CardService.newTextInput()
.setFieldName("password")
.setTitle("Please enter password")
section.addWidget(cleint_id_Input)
section.addWidget(username_Input)
section.addWidget(password_Input)
Logger.log("Input Value%s",cleint_id_Input)
//Login action button
var action = CardService.newAction().setFunctionName('loginCallback');
section.addWidget(CardService.newTextButton().setText('Login').setOnClickAction(action))
card.addSection(section)
Run Code Online (Sandbox Code Playgroud)
我需要"loginCallback"函数中的inputText值
提前致谢
您可以将输入的值检索为JSON对象.修改后的脚本检索输入的值并显示它们.所以请根据您的环境进行修改.
function buildAddOn() {
var card = CardService.newCardBuilder();
card.setHeader(CardService.newCardHeader().setTitle("Login Here"));
var section = CardService.newCardSection()
var cleint_id_Input = CardService.newTextInput()
.setFieldName("client_id")
.setTitle("Please enter clinet id")
var username_Input = CardService.newTextInput()
.setFieldName("username")
.setTitle("Please enter username")
var password_Input = CardService.newTextInput()
.setFieldName("password")
.setTitle("Please enter password")
section.addWidget(cleint_id_Input)
section.addWidget(username_Input)
section.addWidget(password_Input)
Logger.log("Input Value%s",cleint_id_Input)
//Login action button
var action = CardService.newAction().setFunctionName('loginCallback');
section.addWidget(CardService.newTextButton().setText('Login').setOnClickAction(action))
card.addSection(section)
return card.build() // Added
}
// Added
function loginCallback(e) {
return CardService.newCardBuilder()
.setHeader(CardService.newCardHeader().setTitle('sample'))
.addSection(CardService.newCardSection().addWidget(
CardService.newKeyValue().setContent(JSON.stringify(e.formInput, null, " ")))
)
.build();
}
Run Code Online (Sandbox Code Playgroud)
在你的情况,e中loginCallback(e)如下.
{
"formInput": {
"password": "###",
"client_id": "###",
"username": "###"
},
"clientPlatform": "web",
"messageMetadata": {
"messageId": "###",
"accessToken": "###"
},
"formInputs": {
"password": [
"###"
],
"client_id": [
"###"
],
"username": [
"###"
]
},
"parameters": {}
}
Run Code Online (Sandbox Code Playgroud)
如果我误解你的问题,我很抱歉.