我有一个实时文档,可以在我的网站上下载(一份设备手册)。我希望能够进行更改,而这些细微更改对用户不可见,因此我认为使用命名版本将是理想的选择。但是我看不到链接到最新命名版本的方法。
[我确定每次使用版本命名时,我都可以使用Google Script创建第二个文档并将其复制到其中,但是我认为应该有一种更简单的方法。
我当前使用的URL具有以下格式。
https://docs.google.com/document/d/{Document ID}/export?format=pdf
只要我不更改文档,此方法就很好。
有什么想法吗?
谢谢,
Stu
很遗憾,无法使用G Suite API检索命名版本的名称。
Docs API本身没有允许访问修订的方法,而Drive API却没有名称的资源表示,因此无法通过名称本身来标识修订。
如果您需要的版本是最新版本,则可以使用Drive API Revisions: list
方法来检索最新版本,并从资源响应的exportLinks
属性获取指向该版本的导出链接:
function getExportLink() {
var fileId = "<your-file-id>";
var revisions = Drive.Revisions.list(fileId);
var latestRevision = revisions.items[(revisions.items.length - 1)];
var url = "https://docs.google.com/feeds/download/documents/export/Export?id=";
var revision = "&revision=" + latestRevision.id;
var format = "&exportFormat=pdf";
return url + fileId + revision + format;
}
注意:您必须使用Advanced Drive Service v2从Apps脚本中获取修订-激活此导航至Resources > Advanced Google Services...
,然后单击Drive API
旁边的开关,使其显示为on
并变为绿色。
希望对您有帮助!