简体   繁体   中英

Make a copy of file from shared google drive to my google drive with Google Drive API v3 C#

My colleague shared with me a lot of university documents and I want to copy them to my google drive.

I start C# .net core application and Google Drive v3 API.

I have

  var request = _dataService.Files.Get(id);
  request.SupportsAllDrives = true;
  request.Fields = "*";

  return request;

Where dataService

  _dataService = new DriveService(new BaseClientService.Initializer
  {
    ApiKey = settingsData.ApiKey,
    ApplicationName = settingsData.ApplicationName
  });

How to copy files ? He sent me file ids so I have access to that file id. How to make a copy to my google drive ? I didn't find anything in documentation.

Is there any reason why you cannot use the method Copy ?

Google.Apis.Drive.v3.Data.File copiedFile = new Google.Apis.Drive.v3.Data.File();
//This will be the body of the request so probably you would want to modify this
copiedFile.Name = "Name of the new file";

string originFileId = "insert fileId to be copied";

FilesResource.CopyRequest copyRequest = service.Files.Copy(copiedFile, originFileId);
// You can change more parameter of the request here

copyRequest.Execute();

You can modify the body of the request through the File object ( copiedFile ) you can look at the parameters in here .

Make sure that you include all relevant scopes.

If you still have doubts about the fields or methods in C# classes you can take a deeper look at the C# doc for the api .

Also I would suggest to try the Quickstart for .NET Drive API and work from there in case the solution above don't work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM