Google apps script 如何在Google web app中添加Google驱动器选择器

Google apps script 如何在Google web app中添加Google驱动器选择器,google-apps-script,google-drive-api,picker,Google Apps Script,Google Drive Api,Picker,我想做的是在我的Google Web应用程序中显示Google Picker。我已经尝试了很多方法来实现这一点,但没有任何效果 目前,我的代码如下所示: WebApp.html <!-- rest of the code --> <button type="button" id="pick">Pick File</button> </div> <script> function initPicker() {

我想做的是在我的Google Web应用程序中显示Google Picker。我已经尝试了很多方法来实现这一点,但没有任何效果

目前,我的代码如下所示:

WebApp.html

<!-- rest of the code -->

<button type="button" id="pick">Pick File</button>
</div>
    <script>
        function initPicker() {
            var picker = new FilePicker({
                apiKey: "####################",
                clientId: "##########-##########################",
                buttonEl: document.getElementById('pick'),
                onSelect: function(file) {
                    alert('Selected ' + file.title);
                } // onSelect
            }); // var picker
        } // function initPicker()
    </script>

 <!-- rest of the code -->
现在,这段代码显示的是一种弹出窗口,但为空。代码基于

我已经尝试过的是:

  • 将代码块重新定位到服务器端和客户端

  • 使用htmlOutput、htmlTemplate-non这些作品

  • 还有很多我记不清的事情

我想得到的是这个问题的答案:为什么这个代码不显示GooglePicker


提前感谢。

尝试添加呼叫来源和开发者密钥

_showPicker: function() {
  var accessToken = gapi.auth.getToken().access_token;
  this.picker = new google.picker.PickerBuilder()
  .addView(google.picker.ViewId.DOCUMENTS)
  .setAppId(this.clientId)
  .setOAuthToken(accessToken)
  .setCallback(this._pickerCallback.bind(this))

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

  .build()
  .setVisible(true);
},

您看过以下链接中的文档了吗?我已经尝试过这个选项,但是我能显示选择器的唯一方法是在全新的页面上显示它,而不是作为弹出窗口。你有没有收到任何错误?如果是,错误来自哪一行?它是API密钥吗?因为在添加这两项之后,出现了一个错误“API开发者密钥无效”。这是一个浏览器客户端密钥,您可能已经启用了一个API密钥,但您需要专门使用创建和使用浏览器密钥客户端ID。此外,您还需要在控制台中专门启用google picker。如果你已经这么做了,很抱歉。太好了!我也尝试了一些不同的方法来解决这个问题。你可以分享你的其他解决方案,让我使用这个非常简单的脚本,它不使用任何API或客户端ID:。
_showPicker: function() {
  var accessToken = gapi.auth.getToken().access_token;
  this.picker = new google.picker.PickerBuilder()
  .addView(google.picker.ViewId.DOCUMENTS)
  .setAppId(this.clientId)
  .setOAuthToken(accessToken)
  .setCallback(this._pickerCallback.bind(this))

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

  .build()
  .setVisible(true);
},