Class AuthorizationInfo

AuthorizationInfo

An object used to determine whether the user needs to authorize this script to use one or more services, and to provide the URL for an authorization dialog. If the script is published as an add-on that uses installable triggers, this information can be used to control access to sections of code for which the user lacks the necessary authorization. Alternately, the add-on can ask the user to open the URL for the authorization dialog to resolve the problem.

This object is returned by ScriptApp.getAuthorizationInfo(authMode). In almost all cases, scripts should call ScriptApp.getAuthorizationInfo(ScriptApp.AuthMode.FULL), since no other authorization mode requires that users grant authorization.

Methods

MethodReturn typeBrief description
getAuthorizationStatus()AuthorizationStatusGets a value that indicates whether the user needs to authorize this script to use one or more services (for example, ScriptApp.AuthorizationStatus.REQUIRED).
getAuthorizationUrl()StringGets the authorization URL that can be used to grant access to the script.

Detailed documentation

getAuthorizationStatus()

Gets a value that indicates whether the user needs to authorize this script to use one or more services (for example, ScriptApp.AuthorizationStatus.REQUIRED).

// Log the authorization status (REQUIRED or NOT_REQUIRED).
const authInfo = ScriptApp.getAuthorizationInfo(ScriptApp.AuthMode.FULL);
Logger.log(authInfo.getAuthorizationStatus());

Return

AuthorizationStatus — the authorization status


getAuthorizationUrl()

Gets the authorization URL that can be used to grant access to the script. This method returns null if no authorization is required. The page at the URL will close automatically if it is accessed and the script does not require any authorization.

// Log the URL used to grant access to the script.
const authInfo = ScriptApp.getAuthorizationInfo(ScriptApp.AuthMode.FULL);
Logger.log(authInfo.getAuthorizationUrl());

Return

String — a URL that can be used to authorize the script