【问题标题】:Get and Update google docs version [closed]获取和更新谷歌文档版本 [关闭]
【发布时间】:2021-06-06 18:35:00
【问题描述】:

我有一个 google 文档,其中包含使用 UI 添加的多个命名版本,我需要能够

  • 使用 API 获取指向特定版本的文档的 link
  • 使用 API 添加新版本。

其背后的想法是使用link 将文档连接到 git 存储库中的特定提交

在文档中找不到任何参考资料,我在堆栈溢出中发现了一些问题,但没有人给出适当的解决方案。

【问题讨论】:

    标签: google-drive-api google-docs-api


    【解决方案1】:

    问题一的答案:

    使用 API 获取指向特定版本的文档的链接

    不幸的是,在当前阶段,似乎没有检索 URL 以直接打开每个修订版的 Google 文档的方法。 Ref 作为一种解决方法,当为每个修订打开 Google 文档作为导出时,可以使用它。 在这种情况下,您可以使用以下示例请求。

    curl \
      -H 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
      'https://www.googleapis.com/drive/v3/files/{documentId}/revisions?fields=*'
    

    当这个请求运行时,得到如下结果。

    {
      "kind": "drive#revisionList",
      "revisions": [
        {
          "kind": "drive#revision",
          "id": "1",
          "mimeType": "application/vnd.google-apps.document",
          "modifiedTime": "###",
          "published": false,
          "lastModifyingUser": {
            "kind": "drive#user",
            "displayName": "###",
            "photoLink": "###",
            "me": true,
            "permissionId": "###",
            "emailAddress": "###"
          },
          "exportLinks": {
            "application/rtf": "###",
            "application/vnd.oasis.opendocument.text": "###",
            "text/html": "###",
            "application/pdf": "###",
            "application/epub+zip": "###",
            "application/zip": "###",
            "application/vnd.openxmlformats-officedocument.wordprocessingml.document": "###",
            "text/plain": "###"
          }
        },
        ,
        ,
        ,
      ]
    }
    
    • 对于上面的返回值,例如,当检索到第一个索引处exportLinksapplication/vnd.openxmlformats-officedocument.wordprocessingml.document时,即为修订号1的DOCX数据的URL。
    • 在这种情况下,URL 不会公开共享。所以请注意这一点。当您想访问它时,需要登录。当您想让用户访问它时,请与用户分享。

    问题2的答案:

    使用 API 添加新版本。

    很遗憾,在这种情况下,Drive API 的“修订版”中没有创建修订版的方法。但是,当使用 Google Docs API 和 Google Apps 脚本更新文档时,会添加新的修订号。我认为这可能适用于您的情况。

    参考资料:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-04-25
      • 2018-09-27
      • 1970-01-01
      • 2015-04-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多