2017-05-25 71 views
1

我正在創建一個應用程序,要求用戶從其雲端硬盤中選擇一個文件夾。我正在努力設置Picker API。Google Apps腳本 - 在獨立腳本上使用Google的文件選取器

Following this documentation設置我的項目中使用他們的「Hello World」腳本,但改變「devlopedKey」和「clientID的」之後,我測試的代碼收到錯誤:

錯誤401,invalid_client,沒有註冊的起源。

經過四處搜索,我找到了建議將客戶端憑據中的授權JavaScript源設置爲http://localhost:8888。這樣做之後,我收到一個不同的錯誤:

錯誤400,origin_mismatch

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

回答

1

您必須專門爲Google應用程序腳本設置原始值。

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