1

I am using the Drive Picker Api and making a drive picker in a web page. I am showing only the drive files or items that are owned by user (equivalent to using query as owner="me").

Now I am getting an issue in picker: It is also showing shortcuts to files or items for which the user is not owner of the file that is pointed to.

I need to show files owned by the user. Either with a way to filer all shortcuts or ideally only shortcuts to files or items for which user is the owner .

Here is a sample code of picker for owner's file.

//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);
}

Can you help me? How to exclude shortcuts in Picker or show shortcuts for which the user is the owner.

iansedano
  • 6,169
  • 2
  • 12
  • 24
Ashraf
  • 135
  • 10
  • I have just tested this, and for me it works except for those items I have created shortcuts for. Is this the same behavior for you? Apart from the shortcuts, it works perfectly. – iansedano Jun 21 '21 at 13:52
  • @iansedano Thanks for your response. I know It is working for shortcuts created by me. if I have created a shortcuts for a file on which I am not owner, So I do not need this shortcuts in drive picker or I need picker do not show any shortcuts created by me. Is there any solution to show only shortcuts of my own files with own items in drive picker? It means I need only my own files or items only. – Ashraf Jun 21 '21 at 14:30

1 Answers1

1

AFAIK, that is not possible at this time

Even if you use something like this:

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

This will still return all the shortcuts that you created, even if the file that is being pointed to is not owned by you. This is because shortcuts are their own MIME type:

application/vnd.google-apps.shortcut

Source

Feature Request

If you need this on the Picker then you would need to file a feature request using this template:

Picker Feature Request

If you do file a Feature Request, be sure to come back and post it here so that others can vote by "starring" the request.

Additionally, if you file it, be sure to include examples, and as much context and justification as possible, this will give it the best chance to be implemented.

Workaround

I believe you'd need to develop your own JS picker based on the Drive API to have this kind of fine grained control over shortcuts.

iansedano
  • 6,169
  • 2
  • 12
  • 24
  • 1
    Thanks for your suggestion. I have filed a feature request at : https://issuetracker.google.com/issues/191691628 You may check this. – Ashraf Jun 22 '21 at 03:39