Google Apps Script API
    Preparing search index...

    Allows scripts to create state tokens that can be used in callback APIs (like OAuth flows).

    // Reusable function to generate a callback URL, assuming the script has been published as a
    // web app (necessary to obtain the URL programmatically). If the script has not been published
    // as a web app, set `var url` in the first line to the URL of your script project (which
    // cannot be obtained programmatically).
    function getCallbackURL(callbackFunction){
      var url = ScriptApp.getService().getUrl();      // Ends in /exec (for a web app)
      url = url.slice(0, -4) + 'usercallback?state='; // Change /exec to /usercallback
      var stateToken = ScriptApp.newStateToken()
          .withMethod(callbackFunction)
          .withTimeout(120)
          .createToken();
      return url + stateToken;
    }
    
    interface StateTokenBuilder {
        createToken(): string;
        withArgument(name: string, value: string): StateTokenBuilder;
        withMethod(method: string): StateTokenBuilder;
        withTimeout(seconds: number): StateTokenBuilder;
    }
    Index

    Methods