Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When I request list of files by google.api.drive I return one pdf file "How to get started with Drive"

I need to get list of files from google drive with asp.net mvc4 project. Google Drive is used as a file storage for the site. My code:

        const string email = "xxx";
        string path = AppDomain.CurrentDomain.BaseDirectory + "file.p12";
        var certificate = new X509Certificate2(path,"notasecret", X509KeyStorageFlags.Exportable);
        var credential = new ServiceAccountCredential(new ServiceAccountCredential.Initializer(email){
            Scopes = new[] { DriveService.Scope.Drive }

        }.FromCertificate(certificate));
        var service = new DriveService(new BaseClientService.Initializer
        {
            HttpClientInitializer = credential,
            ApplicationName="hikes"
        });
        List<File> result = new List<File>();
        FilesResource.ListRequest request = service.Files.List();
        do
        { 
                FileList files = request.Execute();
                result.AddRange(files.Items);
                request.PageToken = files.NextPageToken;

        } while (!String.IsNullOrEmpty(request.PageToken));

Tried on two different accounts. The result is only one pdf file called "How to get started with Drive". How do I get access to the files of my disk?

like image 697
Владимир Рак Avatar asked Oct 09 '14 17:10

Владимир Рак


1 Answers

You need to share at least one folder from your own Google drive accounts with the service's account email created in Google console (416132713247-aimfq7...hj37795pcpvo3@developer.gserviceaccount.com): Right click > Share with > fill email & permissions.

like image 200
Ronan Avatar answered Nov 12 '22 21:11

Ronan