gpt4 book ai didi

javascript - 谷歌应用程序脚本,用于团队驱动器的谷歌选择器

转载 作者:行者123 更新时间:2023-11-29 21:00:37 24 4
gpt4 key购买 nike

221/5000

您好!目前,我正在尝试为 google team drive 实现 google pikker。此代码适用于我的谷歌驱动器,但如果您将此代码用于 Google Team Drives,请添加参数

.enableFeature(google.picker.Feature.SUPPORT_TEAM_DRIVES)

.setSelectFolderEnabled(true)

在文件显示窗口是空的。

我该如何解决?谢谢!

enter image description here

它应该是这样的:

enter image description here

我认为 OAuth 2.0 有问题。

有一篇关于团队驾驶选择器的好文章 https://developers.google.com/drive/v3/web/picker ,但不使用此参数:

.enableFeature(google.picker.Feature.SUPPORT_TEAM_DRIVES)

.setSelectFolderEnabled(true)

选择器.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()
.setIncludeFolders(true)
.setMimeTypes('application/vnd.google-apps.folder')
.setSelectFolderEnabled(true)
.setEnableTeamDrives(true);

var picker = new google.picker.PickerBuilder()
.addView(docsView)
.enableFeature(google.picker.Feature.SUPPORT_TEAM_DRIVES)
.enableFeature(google.picker.Feature.NAV_HIDDEN)
.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) {
var action = data[google.picker.Response.ACTION];
if (action == google.picker.Action.PICKED) {
var doc = data[google.picker.Response.DOCUMENTS][0];
var id = doc[google.picker.Document.ID];
// Show the ID of the Google Drive folder
document.getElementById('result').innerHTML = id;
/**/

google.script.run.searchFileInFoder(id);
google.script.host.close();
/**/
} else if (action == google.picker.Action.CANCEL) {
google.script.host.close();
}
}

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>

代码.gs

  /*Picker for сhoose folder*/
function showPicker() {
var html = HtmlService.createHtmlOutputFromFile('Picker.html')
.setWidth(600)
.setHeight(425)
.setSandboxMode(HtmlService.SandboxMode.IFRAME);
SpreadsheetApp.getUi().showModalDialog(html, 'Select Folder');
}

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

最佳答案

将您的 docsView 变量更改为这样定义,因此您将 google.picker.viewId.DOCS 包含在 DocsView 的括号内,如下所示:

let docsView = new google.picker.DocsView(google.picker.ViewId.DOCS)
.setEnableTeamDrives(true);

我尝试实现上述问题中的代码,但几乎没有出现控制台错误,而且选择器无法正常工作。可能与 .setOrigin 参数有关。我不能说是你的代码的哪一部分导致了错误,因为我不知道你的控制台日志。但无论如何,下面是我的完整 createPicker() 函数,它适用于我:

function createPicker() {
if (pickerApiLoaded && oauthToken) {
var view = new google.picker.DocsView(google.picker.ViewId.FOLDERS)
.setSelectFolderEnabled(true);
var picker = new google.picker.PickerBuilder()
.enableFeature(google.picker.Feature.SUPPORT_TEAM_DRIVES)
.addView(new google.picker.DocsView(google.picker.ViewId.DOCS)
.setEnableTeamDrives(true))
.addView(google.picker.ViewId.DOCS)
.addView(view)
.setOAuthToken(oauthToken)
.setDeveloperKey(developerKey)
.setCallback(pickerCallback)
.build();
picker.setVisible(true);
}
}

关于javascript - 谷歌应用程序脚本,用于团队驱动器的谷歌选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46658325/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com