title: Return a parameter in Google App Script callback
body: <p>The following example code successfully performs a callback to the Google App Script:</p>
  
  <pre><code>var SCRIPT_ID = "1eC5VsM2vkJXa9slM40MTKTlfARGAGyK1myMCU3AB_-Ox_jGxQaoPM8P2";
  
  function getURL() { return getCallbackURL('testCallback'); }
  
  function getCallbackURL(callback) {
    var state = ScriptApp.newStateToken().withTimeout(3600).withMethod(callback).createToken();
    return 'https://script.google.com/macros/d/'+SCRIPT_ID+'/usercallback?state='+state;
  }
  
  function doGet(e){ return HtmlService.createTemplate(" &lt;div&gt;&lt;p&gt;&lt;a href='&lt;?=getURL()?&gt;' id='start-auth'&gt;&lt;?=getURL()?&gt;&lt;/a&gt;&lt;/p&gt;&lt;/div&gt;").evaluate()); }
  
  function testCallback(e){
    Logger.log('myVariable1= ' + e.parameter.myVariable1); // this doesn't work
    Logger.log('myVariable2= ' + e.parameter.myVariable2); // this doesn't work
    return HtmlService.createHtmlOutput('&lt;b&gt;Success. You can close this window. !&lt;/b&gt;')
  }
  </code></pre>
  
  <p>However I need to return a variable to the "testCallback" method as part of a HttpRepsonse redirect.  I've tried settings a cookie and also setting a header variable in my asp.net C# application as follow:</p>
  
  <pre><code>            HttpCookie cookie = new HttpCookie("myVariable1");
              cookie.Value = "someValue1";
              cookie.Expires = DateTime.Now.AddMinutes(1);
              Response.Cookies.Add(cookie);
              Response.AddHeader("myVariable2", "someValue2");
              Response.Redirect(applicationCallbackUri, true);
  </code></pre>
  
  <p>but it's not clear whether the header or cookie variables are available to Google's callback method:</p>
  
  <pre><code>function testCallback(e){
    Logger.log('myVariable1= ' + e.parameter.myVariable1);
    Logger.log('myVariable2= ' + e.parameter.myVariable2);
    return HtmlService.createHtmlOutput('&lt;b&gt;Success. You can close this window. 
  !&lt;/b&gt;')
  }
  </code></pre>
  
  <p>I've also tried using the .WithArguments method when creating the a new state token, but I'm not sure if its possible for my asp.net application to update the state object's arguments as part of the redirect/return.</p>
  
  <p>I've also tried appending the variable to the Google Callback URL, e.g.
      <a href="https://script.google.com/macros/d/1eC5VsM2vkJXa9slM40MTKTlfARGAGyK1myMCU3AB_-Ox_jGxQaoPM8P2?state=ADEpC8w0dL6mBVmDQHX3XcYcBP0JqQ5_etc&amp;myVariable1=someValue1" rel="nofollow noreferrer">https://script.google.com/macros/d/1eC5VsM2vkJXa9slM40MTKTlfARGAGyK1myMCU3AB_-Ox_jGxQaoPM8P2?state=ADEpC8w0dL6mBVmDQHX3XcYcBP0JqQ5_etc&amp;myVariable1=someValue1</a></p>
  
  <p>However Google throws an "invalid state" error</p>