Javascript ServerClickHandler结果为;遇到错误:必需:必需";

Javascript ServerClickHandler结果为;遇到错误:必需:必需";,javascript,google-apps-script,Javascript,Google Apps Script,在我的Google Apps脚本中,我的ServerClickHandler似乎有问题。 运行我的应用程序并提交按钮时,错误消息为“遇到错误:必需:必需” 有人知道为什么会这样吗 var User = new Object(), Url = new Object(); // Startet die Web-App function doGet() { User.email = Session.getActiveUser().getEmail(); var app = UiApp.cr

在我的Google Apps脚本中,我的ServerClickHandler似乎有问题。 运行我的应用程序并提交按钮时,错误消息为“遇到错误:必需:必需” 有人知道为什么会这样吗

var User = new Object(),
Url  = new Object();
// Startet die Web-App
function doGet() {
  User.email = Session.getActiveUser().getEmail();

  var app = UiApp.createApplication();
  var panel = app.createVerticalPanel();//Create a panel which will hold all the elements
  var longUrlLabel = app.createLabel( 'lange E-Mail hier eingeben - Kurzlink wird dann per E-Mail zugesendet' );
  var longUrlBox = app.createTextBox().setName( 'longUrl' )
                                    .setText( 'http://www.' );
  var longUrlLabelInfo = app.createLabel().setId( 'shortUrlLabelInfo' ).setVisible( false );
  var button = app.createButton( 'Ausführen' );


  var handler = app.createServerClickHandler( 'buttonOnClickListener' );
  //createHandler for the Button-onClick-Event.
  handler.addCallbackElement( panel );
  button.addClickHandler( handler ); //Add this handler to the button 

  //Add all the UI elements to the panel
  panel.add( longUrlLabel )
       .add( longUrlBox )
       .add( button );
  app.add( panel );//Add the panel to the application
  return app;
}

function buttonOnClickListener( eventInfo ) {
  var app;
  Url.long  = eventInfo.parameter.longUrl.toString();
  Url.short = UrlShortener.Url.insert( UrlShortener.newUrl().setLongUrl( Url.short ) );
  sendMail();
  app = UiApp.getActiveApplication();
  app.getElementById( 'longUrlLabelInfo' ).setVisible(true).setText( Url.short );

  return app; 
}

function sendMail() {
  GmailApp.sendEmail( User.email, "UrlShortener", Url.long+" -> "+Url.short );
}
试着这样做:(编辑:我确实改进了用户界面和电子邮件布局,以获得更清晰易读的值+用英语翻译;-)很抱歉,但我的德语很差。(;-)

var User=new Object(),
Url=新对象();
User.email=Session.getActiveUser().getEmail();
函数doGet(){
var app=UiApp.createApplication();
var panel=app.createVerticalPanel().setStyleAttributes({'padding':'40px','backgroundColor':'#fafacc'});
var longUrlLabel=app.createLabel('输入以http://开头的长url,您将立即收到带有短url的电子邮件');
var longUrlBox=app.createTextBox().setName('longUrl').addClickHandler(app.createClientHandler().forEventSource().setText(“”))
.setText('http://').setWidth('500');
var shorturlabel=app.createHTML().setId('shorturlabel').setVisible(false);
var handler=app.createServerHandler('ButtonClickListener').addCallbackElement(面板);
var button=app.createButton('SUBMIT',handler.setStyleAttributes({'border-radius':'5px');
var grid=app.createGrid(8,1).setId('grid'))
.setWidget(0,0,longUrlLabel)
.setWidget(2,0,longUrlBox)
.setWidget(4,0,按钮)
.setWidget(6,0,短URL标签);
返回应用程序添加(面板添加(网格));
}
函数按钮NonClickListener(事件信息){
var app=UiApp.getActiveApplication();
var toShorten=UrlShortener.newUrl().setLongUrl(eventInfo.parameter.longUrl);
var shorted=UrlShortener.Url.insert(toShorten);
Url.short=UrlShortener.Url.insert(toShorten);
Url.long=eventInfo.parameter.longUrl;
sendMail();
app=UiApp.getActiveApplication();
app.getElementById('shortUrlLabel').setVisible(true).setHTML('
  • shortURL='+url.Short.id+'
  • 已发送邮件…
  • '); app.getElementById('grid').setWidget(7,0,app.createAnchor('test(带有重定向警告)'),Url.short.id)); 返回应用程序; } 函数sendMail(){ GmailApp.sendmail(User.email,“UrlShortener”,“Long url(original)='+url.Long+“\n\n\n短url=“+url.short.id”); }

    User.email未在单击处理程序中初始化。Globals只在每次回调期间有效,不在中间,所以在dogetworks之外初始化它们,谢谢!:)编辑问题:不是使用该应用程序的用户接收电子邮件,而是我。所以Gmail App.SeDemail(Ur.Email)总是转到脚本管理员(ME)的电子邮件:(我不理解,因为我在发布应用程序时设置了正确的设置。谢谢,这是一个有趣的功能:-请考虑接受这个答案。它对我来说是有效的,我的其他帐户收到了电子邮件,可以自由地测试这个链接:(这是一个缩写;-))为什么在您的脚本中活动用户接收电子邮件会起作用?GmailApp.sendEmail(user.email,…);将电子邮件一直发送给我,但标题信息中包含正确的目标电子邮件。。。
    var User = new Object(),
    Url  = new Object();
    User.email = Session.getActiveUser().getEmail();
    
    function doGet() {
      var app = UiApp.createApplication();
      var panel = app.createVerticalPanel().setStyleAttributes({'padding':'40px','backgroundColor':'#fafacc'});
      var longUrlLabel = app.createLabel( 'Enter the long url starting with http:// you will receive an email with the short url immediately.' );
      var longUrlBox = app.createTextBox().setName( 'longUrl' ).addClickHandler(app.createClientHandler().forEventSource().setText(''))
      .setText( 'http://' ).setWidth('500');
      var shortUrlLabel = app.createHTML().setId( 'shortUrlLabel' ).setVisible( false );
    
    
      var handler = app.createServerHandler( 'buttonOnClickListener' ).addCallbackElement( panel );
      var button = app.createButton( 'SUBMIT',handler ).setStyleAttributes({'border-radius':'5px'});
    
      var grid = app.createGrid(8,1).setId('grid')
      .setWidget(0,0,longUrlLabel )
      .setWidget(2,0,longUrlBox )
      .setWidget(4,0,button )
      .setWidget(6,0,shortUrlLabel);
    
      return app.add( panel.add(grid));
    }
    
    function buttonOnClickListener( eventInfo ) {
      var app =UiApp.getActiveApplication();
      var toShorten = UrlShortener.newUrl().setLongUrl(eventInfo.parameter.longUrl);
      var shortened = UrlShortener.Url.insert(toShorten);
      Url.short = UrlShortener.Url.insert(toShorten);
      Url.long = eventInfo.parameter.longUrl;
      sendMail();
      app = UiApp.getActiveApplication();
      app.getElementById( 'shortUrlLabel' ).setVisible(true).setHTML('<li>Short url = <b>'+Url.short.id+'</b></li><li>Mail sent ...</li>');
      app.getElementById('grid').setWidget(7,0,app.createAnchor('test (with redirect warning)', Url.short.id));
    
      return app; 
    }
    
    function sendMail() {
      GmailApp.sendEmail( User.email, "UrlShortener", 'Long url (original) = '+Url.long+"\n\n\nShort url = "+Url.short.id);
    }