我正在创建一个应用程序,要求用户从其驱动器中选择一个文件夹。我正在努力设置Picker API。
Following this documentation我使用他们的'Hello World'脚本设置我的项目,但在更改'devlopedKey'和'clientID'后,我测试代码以接收错误:
错误401,invalid_client,没有注册的来源。
在搜索之后,我找到了将客户端凭据中的授权JavaScript来源设置为http://localhost:8888的建议。执行此操作后,我收到一个不同的错误:
错误400,origin_mismatch
很抱歉,如果这是我的一个简单错误,我们将不胜感激。
答案 0 :(得分:3)
您必须专门为google apps脚本设置setOrigin。
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);
以下是文档:https://developers.google.com/apps-script/guides/dialogs#file-open_dialogs