2
votes

when a shared user is login in App. shared file can't access. API return "no files found'.

var SCOPES = ["https://www.googleapis.com/auth/drive.file", "profile"];
function createPermissions(fileId, body) {
  gapi.client.load("drive", "v3", function() {
    gapi.client.drive.permissions
      .create({
        fileId: fileId,
        resource: body
      })
      .then(function(res) {
        //console.log(res);
        Swal.fire("Success!", "File has been success shared!", "success");
        // do something
      })
      .catch(function(err) {
        //console.log(err);
        Swal.fire({
          icon: "error",
          title: "Oops...",
          text: "Something went wrong! Plese try agian later!!",
          footer: ""
        });
        // do something
      });
  });
}

The above code is working fine, the file is successfully shared but the shared user gets email notification of share file and when a shared user clicks on a shared file email file is access in google drive. Ie: Manoj (App owner) upload file in google APP(google drive API) and share file with "Rigal". Rigal gets a shared file email notification and file also display(access ) in his google drive. But when Rigal login in App (google drive API) he can't view (access) shared file. Thanks

1
Do you encounter the same problem if Manoj shares the files manually with Rigal, without using the API? When the shared user clicks in the email on the link to the file that has been shared with him, is the file / his drive being opened with the same account with which the file has been shared? Or maybe the user has a second account? - ziganotschka
Hello, @ziganotschka Yes, I have checked manually to share a file with rigal and it is successfully shared After when I log in with API shared file not display using API. - Ankit
So the file is succesfully shared, but does not show up when Rigal tries to access it programmatically with the API? Can you please provide the code that Rigal uses to access the file? - ziganotschka
Hello, @ziganotschka I following developers.google.com/drive/api/v3/quickstart/js link to get files from google drive. I have change var SCOPES = "googleapis.com/auth/drive.file"; in the above code example. - Ankit
Can the user access the file with different scopes, e.g. https://www.googleapis.com/auth/drive? The documentation developers.google.com/identity/protocols/googlescopes specifies that https://www.googleapis.com/auth/drive.file only allows you to "View and manage Google Drive files and folders that you have opened or created with this app" - ziganotschka

1 Answers

0
votes

Search results for listing files can be filtered by implementing the search query q

  • If Rigal specifies for q 'sharedWithMe' - only the files will be listed, that have been shared with Rigal by someone else.
  • If Rigal addionally specifies '[email protected]' in owners, this will allow to eliminate from the results the files that have been shared with Rigal by someone else.
  • It is not possible to distinguish between files that have been shared with Rigal by Manoj's App, rather than by Manoj manually, unless Monoj's App makes use of a service account, eventually with impersonation, for sharing the file with Rigal.

A sample based on the Drive v3 API quickstart you use:

function listFiles() {
        gapi.client.drive.files.list({
          'q': "sharedWithMe and '[email protected]' in owners"
          'pageSize': 10,
          'fields': "nextPageToken, files(id, name)"
        }).then(function(response) {
          appendPre('Files:');
          var files = response.result.files;
          if (files && files.length > 0) {
            for (var i = 0; i < files.length; i++) {
              var file = files[i];
              appendPre(file.name + ' (' + file.id + ')');
            }
          } else {
            appendPre('No files found.');
          }
        });
      }