Google drive api 使用mimetype应用程序/vnd.Google-apps.document上载Google DriveService API失败

Google drive api 使用mimetype应用程序/vnd.Google-apps.document上载Google DriveService API失败,google-drive-api,google-docs-api,Google Drive Api,Google Docs Api,我正试图上传一个文件到谷歌硬盘,并通过谷歌文档共享/访问该文件。我复制了下面的代码片段。我正在使用谷歌驱动器API V3。它失败时出现错误GoogleApiException: Google.API.Requests.RequestError错误请求[400] 不确定请求中缺少了什么。我尝试了文件的几个附加参数,但它总是返回错误的请求错误。如果有人知道解决方案,请让我知道 string fileType = "application/vnd.google-apps.document&q

我正试图上传一个文件到谷歌硬盘,并通过谷歌文档共享/访问该文件。我复制了下面的代码片段。我正在使用谷歌驱动器API V3。它失败时出现错误GoogleApiException:

Google.API.Requests.RequestError错误请求[400]

不确定请求中缺少了什么。我尝试了文件的几个附加参数,但它总是返回错误的请求错误。如果有人知道解决方案,请让我知道

string fileType = "application/vnd.google-apps.document";
var newFile = new File
      {
          Name = title,
          MimeType = fileType,
          Description= title,          
      };

var uploadProgress = DriveService.Files.Create(newFile, fileStream, fileType);
Google.Apis.Upload.IUploadProgress progress =  uploadProgress.Upload();
我相信在v3中,您不需要将
mimeType
指定为
DriveService.Files.Create()
  • 这与v2中的
    Files.Insert()
    相反,在v2中还需要指定
    Convert=true

  • 改为:
    var uploadProgress=DriveService.Files.Create(newFile,fileStream)

  • 确保您的原始mimeType与谷歌文档一起使用

  • 确保正确构建
    fileStream

我相信在v3中,您不需要将
mimeType
指定为
DriveService.Files.Create()的第三个参数
  • 这与v2中的
    Files.Insert()
    相反,在v2中还需要指定
    Convert=true

  • 改为:
    var uploadProgress=DriveService.Files.Create(newFile,fileStream)

  • 确保您的原始mimeType与谷歌文档一起使用

  • 确保正确构建
    fileStream


我可以问一下您的代码片段来自何处吗?我可以问一下您的代码片段来自何处吗?谢谢您提供ziganotschka的信息。该文档有点误导,它显示出V3支持这一点。您链接的文档包含行
File File=driveService.files().create(fileMetadata,mediaContent)
这相当于我试图解释的内容:它-原始的mimeType进入mediaContent,相应的Google mimeType在
fileMetadata
中指定-因此无需通过将第三个参数传递给
Create()
第二次指定它,我一直在尝试C3中的解决方案,如下所示。API确实需要第三个参数fileType=“application/vnd.google apps.document”var newFile=new File{Name=title,MimeType=fileType,};var uploadProgress=DriveService.Files.Create(newFile,fileStream,fileType).Upload();我的C#代码如下。我尝试了在文件mime类型和创建方法中提供text/plain选项,但总是返回错误请求400。fileType=“application/vnd.google apps.document”;var newFile=newFile{Name=title,MimeType=fileType,};var uploadProgress=DriveService.Files.Create(newFile,fileStream,fileType).Upload();实际上,我想做的是将一个文件上传到google drive(我们已经在现有的应用程序中提供了),并能够通过google Docs API访问相同的文件,这样我们就可以利用文档的功能,如“建议”,但当我尝试使用协作id或文件id访问文件时出错。请告诉我是否有方法通过Google Docs API访问使用Google Drive API(.doc或.docx)上载的文件。感谢您提供ziganotschka的信息。该文档有点误导,它显示出V3支持这一点。您链接的文档包含行
File File=driveService.files().create(fileMetadata,mediaContent)
这相当于我试图解释的内容:它-原始的mimeType进入mediaContent,相应的Google mimeType在
fileMetadata
中指定-因此无需通过将第三个参数传递给
Create()
第二次指定它,我一直在尝试C3中的解决方案,如下所示。API确实需要第三个参数fileType=“application/vnd.google apps.document”var newFile=new File{Name=title,MimeType=fileType,};var uploadProgress=DriveService.Files.Create(newFile,fileStream,fileType).Upload();我的C#代码如下。我尝试了在文件mime类型和创建方法中提供text/plain选项,但总是返回错误请求400。fileType=“application/vnd.google apps.document”;var newFile=newFile{Name=title,MimeType=fileType,};var uploadProgress=DriveService.Files.Create(newFile,fileStream,fileType).Upload();实际上,我想做的是将一个文件上传到google drive(我们已经在现有的应用程序中提供了),并能够通过google Docs API访问相同的文件,这样我们就可以利用文档的功能,如“建议”,但当我尝试使用协作id或文件id访问文件时出错。请告诉我是否有方法通过Google Docs API访问使用Google Drive API(.doc或.docx)上载的文件。