簡體   English   中英

Google Apps腳本 - 在獨立腳本上使用Google的文件選擇器

[英]Google Apps Script - Using Google's file picker on a standalone script

我正在創建一個應用程序,要求用戶從其驅動器中選擇一個文件夾。 我正在努力設置Picker API。

根據此文檔 ,我使用“Hello World”腳本設置項目,但在更改“devlopedKey”和“clientID”之后,我測試代碼以接收錯誤:

錯誤401,invalid_client,沒有注冊的來源。

在搜索之后,我找到了將客戶端憑據中的授權JavaScript源設置為http:// localhost:8888的建議 執行此操作后,我收到一個不同的錯誤:

錯誤400,origin_mismatch

對不起,如果這是我的一個簡單的錯誤,任何幫助將不勝感激。

您必須專門為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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM