'How can an authenticated user access the drive that is publicly accessible?

With this code, I am able to get the files that have been shared to the service account email.

But, when I shared the folder (that was not owned by me, but is publicly accessible) from a different email it is not displayed in the list.

Is there any way an authenticated user can access the drive folder that is publicly accessible, but which I won't own?

var serviceAccountEmail = "";
var certificate = new X509Certificate2(_credentialsService.GetCredentialPath(), "notasecret", X509KeyStorageFlags.Exportable);

ServiceAccountCredential credential = new ServiceAccountCredential(
   new ServiceAccountCredential.Initializer(serviceAccountEmail)
   {
       Scopes = new[] { DriveService.Scope.Drive }
   }.FromCertificate(certificate));


var service = new DriveService(new BaseClientService.Initializer
{
    HttpClientInitializer = credential
});

Getting Drive Details

 Google.Apis.Drive.v3.FilesResource.ListRequest FileListRequest = service.Files.List();

// for getting folders only.
//FileListRequest.Q = "mimeType='application/vnd.google-apps.folder'";
FileListRequest.Fields = "nextPageToken, files(id, name)";
FileListRequest.Corpora = "allDrives";
FileListRequest.Q = "sharedWithMe";
FileListRequest.IncludeItemsFromAllDrives = true;
FileListRequest.SupportsAllDrives = true;

// List files.
IList<Google.Apis.Drive.v3.Data.File> files = FileListRequest.Execute().Files;
List<GoogleDriveFile> FileList = new List<GoogleDriveFile>();

Sharing Process:

I shared the file to the service account email, from my personal google email.

enter image description here

And See it is still not available, the image that I owned only is shared. Which is my problem.

enter image description here



Solution 1:[1]

Sending the link of a publicly viewable file is not the same as sharing the file

Your screen looks like this:


enter image description here


  • This means that you have view-only access to the file
  • If you had edit access to the file, the screen would look as following:

enter image description here


  • Thus, since you are not an editor of the public file, you cannot add another viewer / editor to this file and consecuently it will not appear in the sharedWithMe of the user to whom you sent the email - no matter if this user is an actual suer or a service account

Solution:

If you need to explicitly share the file with the service account, your options are

  • to obtain edit access to the public file (if feasible)
  • create a copy of the respective file onto your own Drive (if copying is not disabled) and share your version explicitly with the service account

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ziganotschka