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

问题描述 投票:0回答:1

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

但每次它都会抛出此错误:“您无权调用DriveApp.getFileById。所需权限:(https://www.googleapis.com/auth/drive.readonly || https://www.googleapis.com/auth/drive)(第3行)。”

我也在app Script.json文件中进行了更改。

这是我在脚本编辑器中编写并从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-apps-script
1个回答
0
投票

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

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

© www.soinside.com 2019 - 2024. All rights reserved.