Google云端硬盘选择器-不显示所有文件夹

时间:2019-08-23 08:13:00

标签: google-apps-script google-drive-api google-picker

我正在使用Google Drive Picker API来促进从Google Spreadsheet中上传文件。 用户报告的问题是不是子文件夹中的所有文件夹都可见或可搜索。

有问题的子文件夹本身具有大量的子文件夹。 (大约1000人以上) 有人知道Drive Picker是否可以显示的文件夹数量有某种限制?

根据要求在下面提供我的代码

function showPicker() {
  var html = HtmlService.createHtmlOutputFromFile('0.2 Picker.html')
      .setWidth(600)
      .setHeight(425)
      .setSandboxMode(HtmlService.SandboxMode.IFRAME);
  SpreadsheetApp.getUi().showModalDialog(html, 'Select Invoice(s)');
}

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

// Picker.html

    <!DOCTYPE html>
    <html>
    <head>
    <link rel="stylesheet" href="https://ssl.gstatic.com/docs/script/css/add-ons.css">
    <script type="text/javascript">
    var DIALOG_DIMENSIONS = {
    width: 600,
    height: 425
    };

    var pickerApiLoaded = false;

    function onApiLoad() {
    gapi.load('picker', {
    'callback': function() {
    pickerApiLoaded = true;
    }
    });
    google.script.run.withSuccessHandler(createPicker)
    .withFailureHandler(showError).getOAuthToken();
    }

    function createPicker(token) {

    if (pickerApiLoaded && token) {

    var docsView = new google.picker.DocsView(google.picker.ViewId.FOLDERS)
    .setIncludeFolders(true)
    .setMimeTypes('application/vnd.google-apps.spreadsheet')
    .setParent("ID_OF_FOLDER_GOES_HERE");


    var picker = new google.picker.PickerBuilder()
    .addView(docsView)
    .enableFeature(google.picker.Feature.NAV_HIDDEN)
    .enableFeature(google.picker.Feature.MULTISELECT_ENABLED)
    .enableFeature(google.picker.Feature.SUPPORT_DRIVES)
    .hideTitleBar()
    .setSize(DIALOG_DIMENSIONS.width - 2, DIALOG_DIMENSIONS.height - 2)
    .setOAuthToken(token)
    .setCallback(pickerCallback)
    .setOrigin('https://docs.google.com')
    .build();

    picker.setVisible(true);

    } else {
    showError('Unable to load the file picker.');
    }
    }

    /**
    * A callback function that extracts the chosen document's metadata from the
    * response object. For details on the response object, see
    * https://developers.google.com/picker/docs/result
    *
    * @param {object} data The response object.
    */
    function pickerCallback(data) {

    //Get the user's response action
    var action = data[google.picker.Response.ACTION];

    //Test if users selected "Picked", if true, do the following:
    if (action == google.picker.Action.PICKED) {

    //Get documents uploaded by google picker 
    var files = data[google.picker.Response.DOCUMENTS];

    //Create an array to house ID's of uploaded documents
    var arrayOfIds = [];

    //For the number of elements in the files array do the following
    for (var i = 0; i < files.length; i++) {

    //Get the id of the current file
    var id = files[i][google.picker.Document.ID]

    //Push id of current file into arrayOfIds
    arrayOfIds.push(id)

    }//END OF FOR LOOP I

    //Call getInvoiceData passing in array of IDs            
    google.script.run.getInvoiceData(arrayOfIds);

    //Close the upload box
    google.script.host.close()

    }//END OF IF STATEMENT

    //Check action does not "Picked", check if action is "Cancel"
    else if (action == google.picker.Action.CANCEL) {

    google.script.host.close();

    }//END OF ELSE IF
    }//END OF FUNCTION

    function showError(message) {
    document.getElementById('result').innerHTML = 'Error: ' + message;
    }

</script>
</head>

<body>
<div>
<p id='result'></p>
</div>
<script type="text/javascript" src="https://apis.google.com/js/api.js?onload=onApiLoad"></script>
</body>
</html>

0 个答案:

没有答案