首页 > 解决方案 > 通过 Google Apps 脚本获取 Google Drive 中文件的下载链接

问题描述

我创建了如下脚本:

function myFunction() {
 let u1 = Drive.Files.get('1234');
 // console.log()
 let u2 = DriveApp.getFileById('1234').getDownloadUrl();
 let u3 = DriveApp.getFileById('1234').getUrl();
}

id 1234 的文件是 Google 驱动器中的电子表格。

我想要一个链接。

https://docs.google.com/spreadsheets/d/1234/export?format=xlsx

除非 id 没有改变,否则这个链接似乎是静态的。但是,我想知道一种使用文件对象的方法来获得此链接的方法。

我以为u2有链接,但它变成了null. 并且u3https://docs.google.com/spreadsheets/d/1234/edit?usp=drivesdk

u1似乎有链接,我实际上可以通过

u1.exportLinks["application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"];

这是获取链接的唯一方法吗?

标签: google-apps-scriptgoogle-sheetsgoogle-drive-api

解决方案


推荐阅读