Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在两张牌之间导航_Javascript_Google Apps Script_Gmail Addons - Fatal编程技术网

Javascript 在两张牌之间导航

Javascript 在两张牌之间导航,javascript,google-apps-script,gmail-addons,Javascript,Google Apps Script,Gmail Addons,我正在制作一个gmail插件,我试图使用谷歌应用程序脚本在gmail广告中的两张卡片之间导航。但是我犯了一个错误 加载项出错。 运行时错误。 对象没有属性 - /​卡片/​标题。[行:42,函数:notifyUser,文件:Code] 这是我的舱单代码 { "oauthScopes": [ "https://www.googleapis.com/auth/gmail.addons.execute", "https://www.googleapis.com/auth/gmail

我正在制作一个gmail插件,我试图使用谷歌应用程序脚本在gmail广告中的两张卡片之间导航。但是我犯了一个错误

加载项出错。 运行时错误。 对象没有属性 - /​卡片/​标题。[行:42,函数:notifyUser,文件:Code]

这是我的舱单代码

{
  "oauthScopes": [
    "https://www.googleapis.com/auth/gmail.addons.execute",
    "https://www.googleapis.com/auth/gmail.readonly",
    "https://www.googleapis.com/auth/script.storage",
    "https://www.googleapis.com/auth/script.external_request",
    "https://www.googleapis.com/auth/spreadsheets"    
  ],
   "urlFetchWhitelist": [
      "https://mail.google.com/",
      "https://sites.google.com/fcpl.biz/fthub/ft-hub/"
    ],
  "gmail": {
    "name": "Finetech",
    "logoUrl": "https://sites.google.com/a/oursrilanka.com/testing-url/gmail-addons/sound.png",
    "contextualTriggers": [{
      "unconditional": {},
      "onTriggerFunction": "buildCard"

    }],
    "openLinkUrlPrefixes": [
      "https://mail.google.com/",
      "https://sites.google.com/fcpl.biz/fthub/ft-hub/"
    ],
    "primaryColor": "#4285F4",
    "secondaryColor": "#4285F4",
    "version": "TRUSTED_TESTER_V2"
  }
}
这是我的code.gs文件

    //Spread Sheet ID
var SS_ID = "181tnith14lu8ttAvtqsU3gHi32-UjcrPqH5Pjuenk5A";

function buildCard(){
    var list=getPost();
    Logger.log(list);
    var card = CardService.newCardBuilder();
    card.setHeader(CardService.newCardHeader().setTitle("<font color=\"#0117a1\"><b>FT News Feed</b></font>"));
    var section = CardService.newCardSection().setHeader("<font color=\"#1257e0\">Announcements</font>");
    for(var i=0; i<list.length ;i++){
      section.addWidget(CardService.newTextParagraph().setText(list[i].para.slice(0,85)+"..."+"<font color=\"#FF0000\">view</font>")); 
    }

    var button = CardService.newTextButton().setText('More Detail').setOpenLink(CardService.newOpenLink().setUrl("https://sites.google.com/fcpl.biz/fthub/ft-hub"));
    section.addWidget(CardService.newButtonSet().addButton(button));
    card.addSection(section);

   var section2 = CardService.newCardSection().setHeader("<font color=\"#1257e0\">OverC </font>");
   section2.addWidget(CardService.newTextParagraph().setText(''));
   card.addSection(section2);

   var section3 = CardService.newCardSection().setHeader("<font color=\"#1257e0\">Finetech Apps</font>");
   section3.addWidget(CardService.newTextParagraph().setText(' '));
      var buttonAction = CardService.newAction()
        .setFunctionName('notifyUser');
  section3.addWidget(CardService.newTextButton()
        .setText('Notify')
        .setOnClickAction(buttonAction));
  card.addSection(section3);

  return card.build();
 }

  function notifyUser() {
   var card = CardService.newCardBuilder();
   var section2 = CardService.newCardSection().setHeader("<font color=\"#1257e0\">OverC </font>");
   section2.addWidget(CardService.newTextParagraph().setText(''));
   card.addSection(section2);

    return card.build();
  }

///////////////////////////////////////////////////////////////////////////////

var ss = SpreadsheetApp.openById(SS_ID);
var sheet = ss.getSheets()[0];

function getPost(){

    var todayDate = Utilities.formatDate(new Date(), "GMT", "MM/dd/yyyy");
    var lastRaw = sheet.getLastRow();
    var list = [];

    //get data from sheet
    for(var i=lastRaw; i > 1; i--){ 
        if(getClosingDate(i) > todayDate){
              var obj = {
                "para": getPara(i),
                "time":getTime(i),
              };
          list.push(obj);
          }          
    }

    return list;
}

function getPara(raw){
  var para = sheet.getRange(raw,3.0).getValue();  
  return para;    
}

function getClosingDate(raw){
     var dueDate = new Date(sheet.getRange(raw,5.0).getValue());
     //Logger.log("Due: "+dueDate);
     //var nRow = row+1;
     dueDate.setDate(dueDate.getDate()+1);
     var closingDate=Utilities.formatDate(dueDate, "GMT", "MM/dd/yyyy");
     return closingDate;   
}

function getTime(raw){
     var time = sheet.getRange(raw, 1.0).getValue().toString();
     var editTime=time.slice(0,24);  
     return editTime;
}
//电子表格ID
var SS_ID=“181tnith14lu8ttAvtqsU3gHi32-UjcrPqH5Pjuenk5A”;
函数buildCard(){
var list=getPost();
Logger.log(列表);
var card=CardService.newCardBuilder();
card.setHeader(CardService.newCardHeader().setTitle(“FT新闻提要”);
var section=CardService.newCardSection().setHeader(“公告”);
对于(var i=0;i 1;i--){
如果(getClosingDate(i)>今天日期){
var obj={
“第(i)款,
“时间”:getTime(i),
};
列表推送(obj);
}          
}
退货清单;
}
函数getPara(原始){
var para=sheet.getRange(原始,3.0).getValue();
返回段;
}
函数getClosingDate(原始){
var dueDate=新日期(sheet.getRange(raw,5.0).getValue());
//Logger.log(“到期日:+dueDate”);
//var nRow=行+1;
dueDate.setDate(dueDate.getDate()+1);
var closingDate=Utilities.formatDate(dueDate,“GMT”,“MM/dd/yyyy”);
返回关闭日期;
}
函数getTime(原始){
var time=sheet.getRange(原始,1.0).getValue().toString();
var editTime=时间切片(0,24);
返回编辑时间;
}

您需要将CardHeader添加到notifyUser方法内创建的卡中

  function notifyUser() {
    var card = CardService.newCardBuilder();
    card.setHeader(CardService.newCardHeader().setTitle("Notify User"));
    var section2 = CardService.newCardSection().setHeader("<font color=\"#1257e0\">OverC </font>");
    section2.addWidget(CardService.newTextParagraph().setText(''));
    card.addSection(section2);
    return card.build();
  }
函数notifyUser(){
var card=CardService.newCardBuilder();
card.setHeader(CardService.newCardHeader().setTitle(“通知用户”));
var section 2=CardService.newCardSection().setHeader(“over”);
第2节addWidget(CardService.newtext段落().setText(“”));
卡片添加部分(第2部分);
return card.build();
}