Google Drive api v3响应为null

时间:2016-09-13 11:22:33

标签: c# .net google-drive-api google-api-client

我想尝试上传文件谷歌驱动器,我的代码在这里:

 public static File UploadFile(DriveService service, string fileName, string filePath, string description, string parent)
{
  var fileMetadata = new File
  {
    Name = fileName,
    MimeType = GetMimeType(fileName),
    Description = description,
    OriginalFilename = fileName,
  };

  FilesResource.CreateMediaUpload request;
  using (var stream = new System.IO.FileStream(filePath, System.IO.FileMode.Open))
  {
      request = service.Files.Create(fileMetadata, stream, GetMimeType(fileName));
      request.Fields = "id";
      request.Alt=FilesResource.CreateMediaUpload.AltEnum.Json;
      request.Upload();
  }
  var file = request.ResponseBody;
  Console.WriteLine("File ID: " + file.Id);


  return null;

}

但是响应正文总是空的,我无法上传。顺便说一下,我在这张照片中看到了错误:

google-api-dotnet-client 1.16.0.0 gzip无效值的格式

任何人都知道如何解决此问题并上传文件谷歌驱动器。

enter image description here

1 个答案:

答案 0 :(得分:1)

看来V3已经替换了CreateMediaUpload的InsertMediaUpload,并且在使用服务帐户时,至少ResponseBody将始终返回为NULL。

这使得很难确定文件的ID,后来发现它可以修改权限或执行其他操作。