Google Drive Picker - select folders to upload

依然范特西╮ 提交于 2019-12-12 05:47:46

问题


I have my picker code as follows:

var mimetypes = "application/vnd.ms-excel," +
                        "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet," +
                        "application/vnd.google-apps.spreadsheet," +
                        "application/vnd.ms-powerpoint," +
                        "application/vnd.openxmlformats-officedocument.presentationml.presentation," +
                        "application/vnd.google-apps.presentation," +
                        "application/vnd.openxmlformats-officedocument.wordprocessingml.document," +
                        "application/msword," +
                        "application/vnd.google-apps.document," +
                        "application/pdf,"+
                        "application/vnd.google-apps.folder";
          var view = new google.picker.View(google.picker.ViewId.DOCS);
          view.setMimeTypes(mimetypes);

         var docsView = new google.picker.DocsView()
          .setIncludeFolders(true) 
          .setMimeTypes('application/vnd.google-apps.folder')
          .setSelectFolderEnabled(true);

       var folderView = new google.picker.View(google.picker.ViewId.FODLERS);
       folderView.setMimeTypes("application/vnd.google-apps.folder");

          var picker = new google.picker.PickerBuilder()
              .enableFeature(google.picker.Feature.MINE_ONLY)
              .enableFeature(google.picker.Feature.NAV_HIDDEN)
              .setAppId(appId)
              .setOAuthToken(oauthToken)
              .addView(view)
              .addView(docsView)
              .addView(folderView)
              .addView(new google.picker.DocsUploadView())
              .setSelectableMimeTypes(mimetypes)
              .setDeveloperKey(developerKey)
              .setCallback(pickerCallback)
              .build();
           picker.setVisible(true);

I have added the view to enable "setSelectFolderEnabled" but still after selecting the folder form Picker View, the "Select" button in the bottom remains disabled. I need the folder Id in callback for further processing. But I am unable to figure out how to enable the button even if a folder is selected.

Does Google Picker API only allow to select files saved in Google Drive ??


回答1:


Just changed my code to this and it works :

 var docsView = new google.picker.DocsView().
                                 setIncludeFolders(true).
                                 setSelectFolderEnabled(true);
          var picker = new google.picker.PickerBuilder()
              .enableFeature(google.picker.Feature.MINE_ONLY)
              .enableFeature(google.picker.Feature.NAV_HIDDEN)
              .setAppId(appId)
              .setOAuthToken(oauthToken)
              .setDeveloperKey(developerKey)
              .addView(docsView)
              .setCallback(pickerCallback)
              .build();
          picker.setVisible(true);



回答2:


Try to add the google.picker.​ViewId.FOLDERS viewId in the addView. I think you can't select folders due to it not being set in the PickerView.Builder. More information about the View Descriptions can be found on the Showing Different Views of the Picker API documentation.

After that, determine if you have write scopes for you to upload files to Drive.



来源:https://stackoverflow.com/questions/35436836/google-drive-picker-select-folders-to-upload

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!