【问题标题】:Make a copy of file from shared google drive to my google drive with Google Drive API v3 C#使用 Google Drive API v3 C# 将文件从共享的谷歌驱动器复制到我的谷歌驱动器
【发布时间】:2019-11-26 13:04:05
【问题描述】:

我的同事与我分享了很多大学文件,我想将它们复制到我的谷歌驱动器。

我启动 C# .net 核心应用程序和 Google Drive v3 API。

我有

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

  return request;

在哪里dataService

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

如何复制文件?他向我发送了文件 ID,因此我可以访问该文件 ID。如何make a copy 到我的谷歌驱动器?我没有在文档中找到任何内容。

【问题讨论】:

  • 没有帮助。我需要制作副本,而不是上传文件!
  • 您可以使用 UI 来完成。单击Shared With Me 全选。 Right Click -> Make a copy
  • 如果我会使用 UI,我不会在这里问。我有数百个文件...我想以编程方式进行

标签: c# google-drive-api


【解决方案1】:

有什么原因不能使用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();

可以通过File对象(copiedFile)修改请求的正文,可以查看here中的参数。

确保包含所有相关范围。

如果您对 C# 类中的字段或方法仍有疑问,可以深入了解C# doc for the api

另外我建议尝试Quickstart for .NET Drive API 并从那里开始工作,以防上述解决方案不起作用。

【讨论】:

  • 需要授权才能做这样的操作
  • 是的,您需要使用正常的 OAuth 流程获得授权。此外,文件需要与您要将文件复制到的帐户共享。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-04-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多