创建指向Google文档的姓氏的PDF链接 [英] Create PDF link to the last named version of a Google Document
问题描述
我有一个实时文档,可以在我的网站上下载(一份设备手册).我希望能够进行更改,而这些细微更改对用户不可见,因此我认为使用命名版本将是理想的选择.但是我看不到链接到最新命名版本的方法.
I have a live document which is available for download on my website (a manual for a piece of equipment). I want to be able to make changes without these minor changes being visible to the user and so thought that using named versions would be ideal. But I can't see a way to link to the most recent named version.
我确定我可以使用Google脚本创建第二个文档,并在每次命名版本时将其复制到其中,但是我认为应该有一种更简单的方法.
I'm sure I could use Google Script to create a second document and duplicate into it every time I name the version, but I was thinking there should be an easier way.
我当前使用的URL格式如下.
The URL I'm currently using is in the following format.
https://docs.google.com/document/d/{Document ID}/export?format=pdf
只要我不对文档进行更改,此方法就可以很好地工作.
This works well as long as I don't make changes to the document.
有什么想法吗?
谢谢
斯图
推荐答案
答案:
很遗憾,无法使用G Suite API检索命名版本的名称.
Docs API本身没有允许访问修订的方法,而Drive API却没有名称的资源表示,因此无法通过名称本身来标识修订.
The Docs API itself doesn't have methods that allow access to revisions, and while the Drive API does, there isn't a resource representation of the name so the revisions can't be identified by name itself.
如果您需要的版本是最新版本,则可以使用Drive API Revisions: list
方法检索最新版本,并从资源响应的exportLinks
属性获取指向该版本的导出链接:
If the version you need is the latest version, you can use the Drive API Revisions: list
method to retrieve the latest revision and get an export link to that from the exportLinks
property of the resource response:
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
并变为绿色.
Note: you have to use the Advanced Drive Service v2 to get Revisions from within Apps Script - to activate this navigate to Resources > Advanced Google Services...
and click the switch next to Drive API
so that it says on
and turns green.
希望对您有帮助!
- Google Documents API Reference
- Download and publish file revisions - Google Drive API
- Google Drive API Revisions Overview
- Google Drive API
Revisions: list
method
这篇关于创建指向Google文档的姓氏的PDF链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!