diff --git a/picker/README.md b/picker/README.md index d8dfd7b26..4efb72ea3 100644 --- a/picker/README.md +++ b/picker/README.md @@ -1,12 +1,5 @@ # File Picker Sample -This sample shows how to create a "file-open" dialog in Google Sheets that -allows the user to select a file from their Drive. It does so by loading -[Google Picker](https://developers.google.com/picker/), a standard G Suite -client-side API for this purpose. More information is available in the Apps -Script guide -[Dialogs and Sidebars in Google Workspace Documents](https://developers.google.com/apps-script/guides/dialogs#file-open_dialogs). +This sample shows how to create a "file-open" dialog in Google Sheets thatallows the user to select a file from their Drive. It does so by loading [Google Picker](https://developers.google.com/picker/), for this purpose. More information is available in the Apps Script guide [Dialogs and Sidebars in Google Workspace Documents](https://developers.google.com/apps-script/guides/dialogs#file-open_dialogs). -Note that this sample expects to be -[bound](https://developers.google.com/apps-script/guides/bound) -to a spreadsheet. +Note that this sample expects to be [bound](https://developers.google.com/apps-script/guides/bound) to a spreadsheet. diff --git a/picker/appsscript.json b/picker/appsscript.json new file mode 100644 index 000000000..bc86e7be2 --- /dev/null +++ b/picker/appsscript.json @@ -0,0 +1,18 @@ +{ + "timeZone": "America/Los_Angeles", + "exceptionLogging": "STACKDRIVER", + "runtimeVersion": "V8", + "oauthScopes": [ + "https://www.googleapis.com/auth/script.container.ui", + "https://www.googleapis.com/auth/drive.file" + ], + "dependencies": { + "enabledAdvancedServices": [ + { + "userSymbol": "Drive", + "version": "v3", + "serviceId": "drive" + } + ] + } + } \ No newline at end of file diff --git a/picker/code.gs b/picker/code.gs index e373d62d9..3346d4214 100644 --- a/picker/code.gs +++ b/picker/code.gs @@ -19,14 +19,10 @@ * Creates a custom menu in Google Sheets when the spreadsheet opens. */ function onOpen() { - try { - SpreadsheetApp.getUi().createMenu('Picker') - .addItem('Start', 'showPicker') - .addToUi(); - } catch (e) { - // TODO (Developer) - Handle exception - console.log('Failed with error: %s', e.error); - } + SpreadsheetApp.getUi() + .createMenu("Picker") + .addItem("Start", "showPicker") + .addToUi(); } /** @@ -34,16 +30,17 @@ function onOpen() { * JavaScript code for the Google Picker API. */ function showPicker() { - try { - const html = HtmlService.createHtmlOutputFromFile('dialog.html') - .setWidth(600) - .setHeight(425) - .setSandboxMode(HtmlService.SandboxMode.IFRAME); - SpreadsheetApp.getUi().showModalDialog(html, 'Select a file'); - } catch (e) { - // TODO (Developer) - Handle exception - console.log('Failed with error: %s', e.error); - } + const html = HtmlService.createHtmlOutputFromFile("dialog.html") + .setWidth(800) + .setHeight(600) + .setSandboxMode(HtmlService.SandboxMode.IFRAME); + SpreadsheetApp.getUi().showModalDialog(html, "Select a file"); +} +/** + * Checks that the file can be accessed. + */ +function getFile(fileId) { + return Drive.Files.get(fileId, { fields: "*" }); } /** @@ -57,12 +54,6 @@ function showPicker() { * @return {string} The user's OAuth 2.0 access token. */ function getOAuthToken() { - try { - DriveApp.getRootFolder(); - return ScriptApp.getOAuthToken(); - } catch (e) { - // TODO (Developer) - Handle exception - console.log('Failed with error: %s', e.error); - } + return ScriptApp.getOAuthToken(); } // [END picker_code] diff --git a/picker/dialog.html b/picker/dialog.html index 4ba2aaa7d..1ade5a4d9 100644 --- a/picker/dialog.html +++ b/picker/dialog.html @@ -13,106 +13,175 @@ -
- - + - /** - * Displays an error message within the #result element. - * - * @param {string} message The error message to display. - */ - function showError(message) { - document.getElementById('result').innerHTML = 'Error: ' + message; - } - - - -