0

I want any user to type his password and his e-mail, and select the file (access BD) in the program. Then press a button to upload the file to his account on google drive.

This is my code at the moment, this create a directory in my count:

    UserCredential Credential;

        Credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
            new ClientSecrets { ClientId = "client_id", ClientSecret = "client_secret" },
            new[] { DriveService.Scope.Drive, DriveService.Scope.DriveFile },
            "user",
            CancellationToken.None,
            new FileDataStore("Drive.Auth.Store")).Result;

        DriveService service = new DriveService(new BaseClientService.Initializer()
        {
            HttpClientInitializer = Credential,
            ApplicationName = "Drive API hoteltactil",
        });

        Google.Apis.Drive.v2.Data.File body = new Google.Apis.Drive.v2.Data.File();
        body.Title = "NewDirectory2";
        body.Description = "Test Directory";
        body.MimeType = "application/vnd.google-apps.folder";
        body.Parents = new List<ParentReference>() { new ParentReference() { Id = "root" } };
        try
        {
            FilesResource.InsertRequest request = service.Files.Insert(body);
            request.Execute();
        }
        catch (Exception ex)
        {
            Console.WriteLine("An error occurred: " + ex.Message);
            Console.Read();
        }
Cœur
  • 37,241
  • 25
  • 195
  • 267

2 Answers2

0

I'm not sure quite what you are asking, but to change ownership of a file I've done this:

 main
 {  
 Permission permission= new Permission();
 permission = share(service, file.Id, <user email>, "user", "owner");
 }

 public static Permission share(DriveService service, String fileId, String value,
  String type, String role)
    {
        Permission newPermission = new Permission();
        newPermission.Value = value;
        newPermission.Type = type;
        newPermission.Role = role;
        try
        {
            return service.Permissions.Insert(newPermission, fileId).Execute();
        }
        catch (Exception e)
        {
            Console.WriteLine("An error occurred: " + e.Message);
        }
        return null;
    }

also, if you are uploading to the root folder, you do not need to specify the body.Parents because root is the base folder (i.e. the automatic parent folder)

Noob
  • 125
  • 1
  • 12
0

I think you don't need to allow users to login yor accont,

yo can rather create a link url then share this link witht the interested users,

that way, they would see only to the concerned file and could download it as well...

Chems Luc
  • 1
  • 2