Friday, March 13, 2015

Change in Apps Scripts DocsListDialog

DocsListDialog is a widget used by only a small fraction of Apps Script projects to provide a Google Drive "file open" dialog in a UI service user interface. In almost all cases, using Google Picker in HTML service is preferable and more secure.

Before September 30, 2014, we require scripts using DocsListDialog to make a small update to improve security.

Specifically, if you use DocsListDialog, youll need to start calling a new method, setOAuthToken(oAuthToken) before you call showDocsPicker(). The new method sets an OAuth 2.0 token to use when fetching data for the dialog, on behalf of the user whose content should be shown.

So long as the app isnt a web app set to execute as "me" (the developer), you can get the necessary OAuth 2.0 token by calling ScriptApp.getOAuthToken(). The example below shows how to convert an old DocsListDialog implementation to the new model.


Old example

function showDialog() {
var app = UiApp.createApplication();

app.createDocsListDialog()
.addCloseHandler(serverHandler)
.addSelectionHandler(serverHandler)
.showDocsPicker();

SpreadsheetApp.getUi()
.showModalDialog(app, );
}

New example

function showDialog() {
var app = UiApp.createApplication();

app.createDocsListDialog()
.addCloseHandler(serverHandler)
.addSelectionHandler(serverHandler)
.setOAuthToken(ScriptApp.getOAuthToken())
.showDocsPicker();

SpreadsheetApp.getUi()
.showModalDialog(app, );
}

To ensure your script continues to work properly, be sure to make this change before September 30.

Posted by Dan Lazin, Googler

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.