首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用Drive 3.0下载Google的修订版?

如何使用Drive 3.0下载Google的修订版?
EN

Stack Overflow用户
提问于 2021-03-03 21:14:29
回答 1查看 216关注 0票数 0

最后,我在c# .NET中为DriveAPI2.0(c#.NET)提供了一个工作解决方案,可以使用下面的过程获得GoogleDocRevision二进制流。这个获得文档修订的过程与仅仅获得一个正常的文档是非常不同的。

在v2中获得Google修订版

  1. OAUTH2授权(所使用的帐户必须具有编辑器权限)
  2. 使用FileId和RevId将GET请求发送到版本2的Drive (这将返回修订元数据)
  3. 将另一个GET请求发送到驱动API的版本2,其中包含在步骤2中为所需导出类型(如docx (或pdf/etc) )获得的“导出”URI,用于修订(这将返回一个很快过期的大量长URI )。
  4. 向临时“导出”URI发送另一个GET请求,以获取步骤2中指定的修订和导出类型的二进制文件流。

有没有办法在驱动器3.0 (v3)中获得Google修订版的二进制流?此功能似乎已被删除。C#或JavaScript、curl或PHP或任何编码语言都可以.

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-03-05 12:58:44

这是从Google获得一个被保护的版本的解决方案。注意: OAUTH2流中的用户必须对文档具有编辑权限。这使用了一个带有下面修改的前端解

代码语言:javascript
复制
   private async Task GetRevisionStream(string accessToken, string fileId, string revId)
    {
        Log("Making API Call to get revision binary stream...");

        // builds the  request
        string userinfoRequestUri = "https://docs.google.com/feeds/download/documents/export/Export?id=" + fileId + "&revision=" + revId + "&exportFormat=docx";

        // sends the request
        HttpWebRequest userinfoRequest = (HttpWebRequest)WebRequest.Create(userinfoRequestUri);
        userinfoRequest.Method = "GET";
        userinfoRequest.Headers.Add(string.Format("Authorization: Bearer {0}", accessToken));
        userinfoRequest.ContentType = "application/x-www-form-urlencoded";
        userinfoRequest.Accept = "Accept=text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";

        // gets the response
        WebResponse userinfoResponse = await userinfoRequest.GetResponseAsync();
        using (StreamReader userinfoResponseReader = new StreamReader(userinfoResponse.GetResponseStream()))
        {
            // reads response body
            System.IO.Stream streamDoc = userinfoResponseReader.BaseStream;
            var fileStream = File.Create("d:\\test.docx");
            streamDoc.CopyTo(fileStream);
            fileStream.Flush();
            fileStream.Close();
        }
    }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66465017

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档