【问题标题】:Google app script,gmail addon get TextInput value谷歌应用脚​​本,gmail插件获取TextInput值
【发布时间】:2018-02-08 07:46:37
【问题描述】:

我已经使用谷歌脚本创建了简单的 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)

我需要“loginCallback”函数中的 inputText 值

提前致谢

【问题讨论】:

    标签: google-apps-script gmail-addons


    【解决方案1】:

    您可以将输入的值作为 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();
    }
    

    输入值:

    在您的情况下,loginCallback(e) 中的e 如下。

    {
        "formInput": {
            "password": "###",
            "client_id": "###",
            "username": "###"
        },
        "clientPlatform": "web",
        "messageMetadata": {
            "messageId": "###",
            "accessToken": "###"
        },
        "formInputs": {
            "password": [
                "###"
            ],
            "client_id": [
                "###"
            ],
            "username": [
                "###"
            ]
        },
        "parameters": {}
    }
    

    如果我误解了你的问题,我很抱歉。

    【讨论】:

    • 我有一个小问题,打开电子邮件时如何打开插件,无需点击插件图标
    • @Robert 我认为这对我来说不是一个小问题。对不起。我还没有解决方案。当我有它时,我会告诉你的。
    • @Robert 我真的很抱歉。顺便说一句,我评论了你的另一个问题。我可以得到你的答复吗? stackoverflow.com/questions/48561117/…
    • @Robert 我看到了。但我无法理解你想做什么。对不起。当用户使用newTextInput() 输入文本时,您要更改该值吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-05-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多