谷歌应用程序脚本中的Google选择器方法“setSelectableMimeTypes不是函数”错误

时间:2017-08-07 06:37:32

标签: google-apps-script google-picker

我正在尝试在Google应用脚本中使用Google picker API,以允许用户选择要上传文档的文件夹。我使用以下代码

HTML文件

function change_destination()
{
 gapi.load('picker', {'callback': function(){pickerApiLoaded = true;}}); 
 google.script.run.withSuccessHandler(createPicker).getOAuthToken();
}
function createPicker(token) 
{
   var docsView = new google.picker.DocsView().setSelectFolderEnabled(true).setParent('root');
   var callback = function(data) 
   {
    if (data.action == google.picker.Action.PICKED)
    {
     var doc = data.docs[0];
     console.log("You picked " + doc.id);
    }
   };
   var picker = new google.picker.PickerBuilder().setSize("650","470").setOAuthToken(token).addView(docsView).setOrigin('https://docs.google.com').setCallback(callback).build();
   picker.setSelectableMimeTypes('application/vnd.google-apps.folder');
   picker.setVisible(true);
}


 <script type="text/javascript" src="https://apis.google.com/js/api.js"></script>

CODE.gs

function getOAuthToken() 
{
  return ScriptApp.getOAuthToken();
}

我收到以下错误“setSelectableMimeTypes不是函数”

1 个答案:

答案 0 :(得分:0)

您需要在构建选择器之前设置setSelectableMimeTypes

var picker = new google.picker.PickerBuilder()
       .setSize("650","470")
       .setSelectableMimeTypes('application/vnd.google-apps.folder') //not sure about this Mime type
       .setOAuthToken(token)
       .addView(docsView)
       .setOrigin(google.script.host.origin)
       .setCallback(callback)
       .build()
   picker.setVisible(true);

仅在选择器视图中显示文件夹。

 var docsView = new google.picker.DocsView(google.picker.ViewId.FOLDERS).setParent('root');
   var picker = new google.picker.PickerBuilder()
       .setSize("650","470")
       .setOAuthToken(token)
       .addView(docsView)
       .setOrigin(google.script.host.origin)
       .setCallback(callback)
       .build()
   picker.setVisible(true);