0

To all Google Apps experts - please help me solve this. I'm rather stuck and I've not found any explanation yet on why this problem exists at all. I've included a live example to demonstrate the problem.

The problem may be view at this location ... https://sites.google.com/a/growthhq.net/faulty-picker/

A Google Apps script made available in a Google Sites using the Apps Script gadget has stopped functioning recently. The crazy thing is that the app works perfectly using the 'dev' and 'exec' urls for the app directly, but when embedding the app in Sites (with the 'exec' url and Apps Script gadget), and the button is clicked, the form comes up blank.

I know that the UiApp is deprecated (sadly, this had some good attributes) but I don't want to change the rest of the code at this stage.

What can I do to get the Picker to show correctly in sites? Is the referrer inadequately specified? I'm at a total loss.

The activated referrers are:
*.google.com
*.googleusercontent.com

I have extracted (and simplified) the code portions for testing purposes. This working test code follows:

 // refer to https://developers.google.com/apps-script/guides/dialogs#file-open_dialogs for setting up OAuth

    function doGet()
    {
      var app = UiApp.createApplication();
      var buttonHandler = app.createServerHandler('utilityPicker');
      var button = app.createButton('Open Picker', buttonHandler)
      app.add(button);
      return app;
      // This is a dummy to activate
      DriveApp.getRootFolder();
    }

    function utilityPicker(e){

      var app = UiApp.getActiveApplication();
      var authToken = ScriptApp.getOAuthToken();
      Logger.log(authToken);

      var docPicker = app
      .createDocsListDialog()
      .setOAuthToken(authToken)
      .setDialogTitle('Select a Google Spreadsheet or Form to be used by this Workspace')
      .setMultiSelectEnabled(true)
      .addView(UiApp.FileType.FOLDERS)
      .showDocsPicker()
      ;

      Logger.log(docPicker);

      docPicker.addView(UiApp.FileType.SPREADSHEETS);

      var handler = app.createServerHandler('pickerPrimarySpreadsheet');

      docPicker.addSelectionHandler(handler);
      return app;
    }

    function pickerPrimarySpreadsheet(e)
    {
      Logger.log(e.parameter);
    }

Please help.

Franco B
  • 116
  • 7
  • Have you tried to use the chrome dev tools to see the behavior of the code? Also kindly double check [deploying web app](https://developers.google.com/apps-script/guides/web?csw=1#deploying_a_script_as_a_web_app) if you have properly deployed your app to your site. – Mr.Rebot May 27 '16 at 07:32
  • I've checked the deployment. You can see this behaviour here ... https://sites.google.com/a/growthhq.net/faulty-picker/ But I'm not sure what to look for with the Chrome Dev tools as this is running as Google Apps Script - and so effectively off the Google server. You can also see the correct behaviour with the deployed link. – Franco B May 28 '16 at 07:48

1 Answers1

0

got the same problem,

found some google group forum where some people had to add

  .setOrigin('https://script.google.com')

to the pickerbuilder

still does not solve my problem, if u got a working solution to use on google sites please share