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;
}
Allows scripts to create state tokens that can be used in callback APIs (like OAuth flows).