0

I get the following ERROR

Google Scripts error

SyntaxError: Unexpected token < (line 119, file "Code")

Doesn't look to me like there are any extra chevrons.

http://prntscr.com/rvzsqd

   "{ ?> <?!= <p><span style='color:green'>Authorized Successfully</span></p> } else {?> <?!= <p><span style='color:red'>Not Authorized</span></p> }").evaluate()
TheMaster
  • 45,448
  • 6
  • 62
  • 85
  • post code text and not image. See [ask] – TheMaster Apr 09 '20 at 10:08
  • 1
    It would be nicer if you could provide your code as an editable document so that the community could test your code without having to retype it, but the first thing visible at the first glance is that the content of line 119 begins with a double quote but ends with a single quote. – ziganotschka Apr 09 '20 at 10:08
  • I've added the problem line – Tomas Forsythe Apr 09 '20 at 10:56

1 Answers1

2

Try using the following for the string template. I think the problem is how you use the <?! syntax.

var template = "<b><a href='<?= getService().getAuthorizationUrl() ?>' target='_blank'>Click to Authorize</a></b><br/><? if (getService().hasAccess()) { ?> <p><span style='color:green'>Authorized Successfully</span></p> <? } else { ?> <p><span style='color:red'>Not Authorized</span></p> <? } ?>";

It's also a bit cleaner if you keep a separate HTML template file (I much prefer that, even for simple pages).

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
    <b>
      <a href='<?= getService().getAuthorizationUrl() ?>' target='_blank'>Click to Authorize</a>
    </b>
    <br/>
    <? if (getService().hasAccess()) { ?> 
      <p>
        <span style='color:green'>Authorized Successfully</span>
      </p>
    <? } else { ?> 
      <p>
        <span style='color:red'>Not Authorized</span>
      </p> 
    <? } ?>
  </body>
</html>
Nimantha
  • 6,405
  • 6
  • 28
  • 69
Steve
  • 66
  • 1