google-drive-api - 获取和更新谷歌文档版本
问题描述
我有一个 google 文档,其中包含使用 UI 添加的多个命名版本,我需要能够
- 使用 API获取
link
指向特定版本的文档 - 使用 API 添加新版本。
其背后的想法是使用它link
来将文档连接到 git 存储库中的特定提交
在文档中找不到任何参考,我在堆栈溢出中发现了一些问题,但没有人给出正确的解决方案。
解决方案
问题 1 的答案:
使用 API 获取指向特定版本的文档的链接
不幸的是,在当前阶段,似乎没有检索 URL 以直接打开每个修订版的 Google 文档的方法。参考作为一种解决方法,当为每个修订打开 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": "###"
}
},
,
,
,
]
}
- 对于上面的返回值,例如,当第一个索引被检索到时
application/vnd.openxmlformats-officedocument.wordprocessingml.document
,exportLinks
即为修订号的 DOCX 数据的 URL1
。 - 在这种情况下,该 URL 不会公开共享。所以请注意这一点。当您想访问它时,需要登录。当您想让用户访问它时,请与用户共享。
问题 2 的答案:
使用 API 添加新版本。
在这种情况下,不幸的是,在 Drive API 的“修订版”中没有创建修订版的方法。但是,当使用 Google Docs API 和 Google Apps 脚本更新文档时,会添加新的修订号。我认为这可能适用于您的情况。
参考:
推荐阅读
- ios - 应用程序通过 MDM 分发时的 Key Chain 数据丢失
- javascript - 如何将 angular2+ 应用程序作为简单的 JS 文件集成到现有的 HTML 站点中
- graph - 确定是否在正在运行的计划任务中的方法?
- python - 获取 AttributeError:“NoneType”对象没有属性“键盘”,
- d3.js - 如何获取 D3 Axis 的路径字符串
- java - Spring 数据 Neo4j + Kotlin 上的日期转换器
- jsf - 如何使用项目模板创建基于集合的组合?
- php - 动态 authTimeout:不覆盖 Yii2 中先前的 authTimeout 值
- c++ - 在同一个线程的同一个实例上多次调用 shared_future::get() 是否合法?
- javascript - 在 useEffect 中反应 setState 导致无限渲染周期