无法使用DriveApp.getFileById(id).getLastUpdated();

时间:2019-04-18 08:51:28

标签: google-apps-script

我想知道文件“ https://drive.google.com/open?id=XYZ”上文件的最新更新日期。该地址存在于我的工作表的A1单元格中。

但是每次抛出此错误时:“您没有调用DriveApp.getFileById的权限。所需的权限:({https://www.googleapis.com/auth/drive.readonly || https://www.googleapis.com/auth/drive)(第3行)。”

我也在appScript.jason文件中进行了更改。

这是我在脚本编辑器中编写的代码,并从B1单元调用:

function useThis(url){
    var id = getIdFromUrl(url);
  return DriveApp.getFileById(id).getLastUpdated();
}

function getIdFromUrl(url) { 
  return url.match(/[-\w]{25,}/); 
}

另外,我的appscript.json看起来像这样:

{
  "timeZone": "Asia/Kolkata",
  "dependencies": {
  },
  "exceptionLogging": "STACKDRIVER",
  "oauthScopes": [
    "https://www.googleapis.com/auth/spreadsheets.readonly",
    "https://www.googleapis.com/auth/userinfo.email"
  ]
}

有没有一种方法可以解决此问题。还是任何其他更简单的方法来获取Google驱动器中文件的最后更新日期?

1 个答案:

答案 0 :(得分:0)

自定义功能不适用于您的用例,因为它们只能调用不需要访问个人数据的服务。参见GAS documentation on custom functions

  

如果您的自定义函数抛出错误消息,您没有   允许调用X服务。该服务需要用户授权   因此无法在自定义函数中使用。