This describes how to implement goa in a sidebar. The example will assume that the authorization process should be repeated for each new user (like a web app published in Accessing as the user running the script) The library, cGoa, is available under this project key. MZx5DzNPsYjVyZaR67xXJQai_d-phDA33 Goa -vs- gapiIf you are creating a sidebar, you can of course use the gapi library to run client side, but goa allows you to create an infrastructure that works server side, to keep your credentials more securely and also to be able to use it for both server and client side purposes. The goa dialog can be customized if you want to make it more the style of your add-on or sidebar content, since the default content is designed for a web app, or since the dialog only happens once, you may want to just leave it as is. Of course if you are using a service account, there is no dialog anyway, and if you are running the sidebar 'as you', then the dialog would only happen once with you - not with each user. Setting everything upThere is no difference between setting up goa for a sidebar or a webapp, and the setup in the Google Developer console is also exactly the same. You still need a one-off initialization of your credentials, like this, which you can run once and then remove from your project. I've downloaded my credentials and want goa to read them from drive. You can enter the credentials directly if you prefer, as described in other examples. The scopes should be provided here for whatever you want to get to. // force a drive auth // DriveApp.getFileById(id) function oneOff() { cGoa.GoaApp.setPackage (PropertiesService.getScriptProperties() , cGoa.GoaApp.createPackageFromFile (DriveApp , { packageName: 'drivedemo', fileId:'0B92ExLh4xxxxxbWtRdWhtanc', scopes : cGoa.GoaApp.scopesGoogleExpand (['drive.readonly']), service:'google', reset:new Date().getTime() })); };
|
Services > Desktop Liberation - the definitive resource for Google Apps Script and Microsoft Office automation > OAuth2 for Apps Script in a few lines of code >