1

我正在使用 Drive Picker Api并在网页中制作驱动器选择器。我只显示用户拥有的驱动器文件或项目(相当于使用 query as owner="me")。

现在我在选择器中遇到了一个问题:它还显示了用户不是所指向文件的所有者的文件或项目的快捷方式。

我需要显示用户拥有的文件。要么用一种方法来归档所有快捷方式,要么理想情况下只提供用户是所有者的文件或项目的快捷方式。

这是所有者文件选择器的示例代码。

//The API developer key obtained from the Google Cloud Console.
var developerKey = "{developerkey value}";

// The Client ID obtained from the Google Cloud Console.
var clientId = "{clientId value}";

// Scope to use to access user's Drive.
var scope = [
  "https://www.googleapis.com/auth/drive.file",
  "https://www.googleapis.com/auth/userinfo.email",
];

var pickerApiLoaded = false;
var oauthToken;

// Use the API Loader script to load google.picker and gapi.auth

function onApiLoad() {
  gapi.load("auth", { callback: onAuthApiLoad });
  gapi.load("picker", { callback: onPickerApiLoad });
}

function onAuthApiLoad() {
  window.gapi.auth.authorize(
    {
      client_id: clientId,
      scope: scope,
      immediate: false,
    },
    handleAuthResult
  );
}

function onPickerApiLoad() {
  pickerApiLoaded = true;
  createPicker();
}

function handleAuthResult(authResult) {
  if (authResult && !authResult.error) {
    oauthToken = authResult.access_token;
    createPicker();
  }
}
// Create and render a Picker object.
function createPicker() {
  var DocsView = new google.picker.DocsView(
    google.picker.ViewId.DOCS
  ).setOwnedByMe(true);
  var picker = new google.picker.PickerBuilder()
    .enableFeature(google.picker.Feature.MULTISELECT_ENABLED)
    .enableFeature(google.picker.Feature.SUPPORT_DRIVES)
    .addView(DocsView)
    .addView(new google.picker.DocsUploadView())
    .setDeveloperKey(developerKey)
    .setOAuthToken(oauthToken)
    .setCallback(pickerCallback)
    .build();
  picker.setVisible(true);
}

你能帮助我吗?如何在选取器中排除快捷方式或显示用户为其所有者的快捷方式。

4

1 回答 1

1

AFAIK,目前这是不可能的

即使你使用这样的东西:

view.setQuery('owner="me"')

即使指向的文件不属于您,这仍将返回您创建的所有快捷方式。这是因为快捷方式是它们自己的 MIME 类型:

application/vnd.google-apps.shortcut

资源

功能要求

如果您在 Picker 上需要此功能,则需要使用此模板提交功能请求:

选择器功能请求

如果您确实提交了功能请求,请务必回来并在此处发布,以便其他人可以通过“加星标”请求进行投票。

此外,如果您提交它,请务必包含示例,以及尽可能多的上下文和理由,这将为它提供最佳实施机会。

解决方法

我相信您需要基于 Drive API 开发自己的 JS 选择器,以便对快捷方式进行这种细粒度的控制。

于 2021-06-21T16:00:13.510 回答