I am using following service code to retrieve folders of the users.
I enabled the drive api and want to use service account…
There are folders in drive but Execute returns none.
What might be missing?
using Google.Apis.Auth.OAuth2;
using Google.Apis.Drive.v3;
using Google.Apis.Services;
namespace GoogleDriveService.Business.Services;
public class GoogleApiDriveService
{
private DriveService _driveService;
public GoogleApiDriveService()
{
var credentialsFilePath = "myservice-12aaae22210a.json";
GoogleCredential credential = GoogleCredential.FromFile(credentialsFilePath)
.CreateScoped([DriveService.Scope.Drive,
DriveService.Scope.DriveFile,
DriveService.Scope.DriveReadonly]);
var initializer = new BaseClientService.Initializer { HttpClientInitializer = credential };
_driveService = new DriveService(initializer);
}
public List<Google.Apis.Drive.v3.Data.File> GetFolders()
{
var request = _driveService.Files.List();
request.IncludeItemsFromAllDrives = true;
request.SupportsAllDrives = true;
request.Q = "mimeType='application/vnd.google-apps.folder'";
var result = request.Execute();
return result.Files.ToList();
}
}
I enabled the drive api, download the service account key, and run the code.
New contributor
TalTrade is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.