Google Drive Picker ViewId.SPREADSHEET显示电子表格和表单

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Google Drive Picker ViewId.SPREADSHEET显示电子表格和表单相关的知识,希望对你有一定的参考价值。

有没有办法将Google云端硬盘选择器限制为仅限电子表格。我正在添加电子表格视图ID(根据Google文档中的以下脚本),但它会同时显示表单和表单。

function createPicker(token) {
  if (pickerApiLoaded && token) {
    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)
        .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);
  } else {
    showError('Unable to load the file picker.');
  }
}
答案

首先,创建一个视图(注意view.setMimeTypes):

// Instruct Picker to display only spreadsheets in Drive. For other
// views, see https://developers.google.com/picker/docs/#otherviews
var view = new google.picker.DocsView(google.picker.ViewId.SPREADSHEETS);
view.setMimeTypes('application/vnd.google-apps.spreadsheet');
view.setIncludeFolders(true);

然后将视图添加到选择器:

var picker = new google.picker.PickerBuilder().addView(view)
另一答案

我认为你可以通过setting the MIME类型来做到这一点。可以找到MIME类型here.

PickerBuilder.setSelectableMimeTypes(string)

以上是关于Google Drive Picker ViewId.SPREADSHEET显示电子表格和表单的主要内容,如果未能解决你的问题,请参考以下文章

Google Drive Picker (JavaScript) 不适合移动设备/响应式

错误:Google Drive Picker 今天停止加载

在google drive使用google.colab云服务

Google Drive 范围 drive.file 不足以将应用拥有的文件复制到应用用户的 Google Drive

Google Drive API失败,因为库的google.drive功能不存在

通过 Google Drive API 从本地 CSV 文件创建 Google Drive 电子表格