Parag Jadhav
Parag Jadhav

Reputation: 1899

How to use user properties in app script add on executing in AuthMode.NONE?

I'm developing a Google Sheet Add On, but running into some troubles.

I'm tyring to access User Properties, as per the Google App Script Add On documentation User Properties are only accessible if app scirpt is executed in AuthMode.LIMITED.

So my question = is there any other way to get use User Properties in onInstall method?

Note: App script is not bounded to Google Spreadsheet, it's a standalone script.

Upvotes: 0

Views: 802

Answers (1)

Spencer Easton
Spencer Easton

Reputation: 5782

From the Apps Script Documentation found at:

https://developers.google.com/apps-script/add-ons/lifecycle#installing

Installing

When an add-on is installed from the store, its onInstall(e) function runs in AuthMode.FULL. This allows the add-on to run a complex setup routine, but it’s important to also use onInstall(e) to create menu items, since the document is already open and thus your onOpen(e) function hasn’t run. For convenience, you can just call onOpen(e) from onInstall(e), as shown in this sample:

function onInstall(e) {
  onOpen(e);
  // Perform additional setup as needed.
}

The authorization life cycle can be confusing:
onInstall() run only the one time when the add-on is installed. It runs in FULL access mode so you have access to all Apps Script services.

onOpen() runs every subsequent time you open a document after the user installs the add-on.

onOpen() can be in two modes NONE or LIMITED.

NONE: The user has installed the add-on previously, but has not enabled it for the current document. At this point all you can do is create menu items. To enable the add-on for the current document the user must select one of your menu items. Once it is enabled it is always enabled for that document( unless your addon changes OAuth scopes and has to be reauthorized by the user ).

LIMITED: The user has enabled the add-on for the current document, but has not engaged your add-on through its menu or UI. You have full access to the document UI and can access the user propertiesservice.

Upvotes: 4

Related Questions