0

I am trying to open the selected file from google drive picker in incognito mode, but it is asking to sign in accounts. I want that file as a public file. Without logging in our account, we should access it.

My picker function in typescript,

createPicker(): void {
    var uploadView = new window["google"].picker.DocsUploadView();
    const view = new window["google"].picker.View(
      window["google"].picker.ViewId.DOCS
    );
    const picker = new window["google"].picker.PickerBuilder()
      .enableFeature(window["google"].picker.Feature.SIMPLE_UPLOAD_ENABLED)
      .enableFeature(window["google"].picker.Feature.MULTISELECT_ENABLED)
      .setDeveloperKey( this.googleDriveApiKey)
      .setAppId(this.googleDriveProjectId)
      .addView(view)
      .addView(uploadView)
      .setOAuthToken(this.accessToken)
      .setCallback(this.pickerCallback.bind(this))
      .build();
    picker.setVisible(true);
  }

Drive picker enter image description here

enter image description here

  • 1
    Its not possible, [the Google Picker API](https://developers.google.com/drive/picker/guides/overview) uses OpenID OAuth to get access to the files. However you can get a list of your files using `files.list` from the [Google Drive API](https://developers.google.com/drive/api/v3/reference/files/list). Check out [this answer](https://stackoverflow.com/a/38298877/17447) – naveen Dec 13 '22 at 05:58

2 Answers2

0

As mentioned by naveen, you need to be authenticated as an end user to access files via Picker. It's not an optional step.

Reference:

Iamblichus
  • 18,540
  • 2
  • 11
  • 27
0

In the picker callback function, after we picked the files, we can set permissions to it.

 if(data && data['docs']) {
          data['docs'].forEach((file)=>{
            var body = {
              'type': 'anyone',
              'role': 'reader'
            }
            var request = window['gapi'].client.drive.permissions.create({
              'fileId': file.id,
              'resource': body
              });
              request.execute(function(resp) {});
          });

This code make all the selected files to be accessible without signing in.