I'm creating a application that requires the user to select a folder from their Drive. I'm struggling to set up the Picker API.
Following this documentation I set up my project using their 'Hello World' script but after changing the 'devlopedKey' and 'clientID', I test the code to receive the error:
Error 401, invalid_client, no registered origin.
After searching around I found suggestions to set the Authorised JavaScript origin within the client credential to http://localhost:8888. After doing this I receive a different error:
Error 400, origin_mismatch
Sorry if this is a simple mistake of mine, any help would be appreciated.
You have to setOrigin specifically for google apps script.
var picker = new google.picker.PickerBuilder()
// Instruct Picker to display only spreadsheets in Drive. For other
// views, see https://developers.google.com/picker/docs/#otherviews
.addView(google.picker.ViewId.SPREADSHEETS)
// Hide the navigation panel so that Picker fills more of the dialog.
.enableFeature(google.picker.Feature.NAV_HIDDEN)
// Hide the title bar since an Apps Script dialog already has a title.
.hideTitleBar()
.setOAuthToken(token)
.setDeveloperKey(DEVELOPER_KEY)
.setCallback(pickerCallback)
//THIS IS THE IMPORTANT LINE FOR YOU
.setOrigin(google.script.host.origin)
// Instruct Picker to fill the dialog, minus 2 pixels for the border.
.setSize(DIALOG_DIMENSIONS.width - 2,
DIALOG_DIMENSIONS.height - 2)
.build();
picker.setVisible(true);
Here is the documentation: https://developers.google.com/apps-script/guides/dialogs#file-open_dialogs