【问题标题】:Can't access Google Drive from Google Apps Script without a paid account?如果没有付费帐户,就无法从 Google Apps 脚本访问 Google Drive?
【发布时间】:2021-09-02 13:37:29
【问题描述】:

我似乎无法使用 Google Apps Script Drive 服务访问我的 Google Drive。 这:DriveApp.getFolderById('1Evf...Kein') 没有返回任何值,只是返回 null。

例如,我的库中的这个函数曾经可以工作,但现在在调用 DriveApp 时什么也不返回:

function getFileByNameInFolder(folderID, fileName) {
  var folder = DriveApp.getFolderById(folderID);
  var files = folder.getFiles();
  
  console.log(folder);
  console.log(files);
  while (files.hasNext()) {
    console.log(file.getName());
   var file = files.next();
    if (file.getName() == fileName) {
     return file; 
    }
  }
  return undefined;
}

console.lor 中的结果:

禁止使用 DriveApp 服务。

我尝试使用独立的应用程序脚本和工作表绑定的应用程序脚本 - 不工作。

我确信它在过去对我过去的项目有效!

仔细阅读,Google 是否有可能阻止使用这些服务,除非您使用它们的某个付费帐户(Google Workspaces 或 Google Cloud)?

还是我错过了什么?

【问题讨论】:

  • Google 没有阻止在我的免费帐户中使用应用脚本
  • 您还缺少其他东西。请分享您的代码。
  • 库珀。只有某些服务被阻止 - 总体上没有 GAP。 DriveApp 不再工作了。对吗?
  • 能否提供截图或示例执行日志?我在我的 gmail 帐户上尝试过,它在我身边工作

标签: google-apps-script google-drive-api


【解决方案1】:

您的 DriveApp 服务没有停止工作。根据您的代码, 预计console.log(folder);console.log(files);会在执行日志中显示{},因为您没有使用console.log(formatOrObject, values)在执行日志中成功记录Apps Script对象。

{} 使用控制台显示console.log(folder); 并不意味着 DriveApp 服务不工作。您可以通过将其替换为 Logger.log(folder) 来验证这一点。您的代码失败的主要问题是因为您调用了console.log(file.getName());file 变量尚未使用Folder 对象定义/初始化(files.next() 的返回)。

应该是这样的:

  while (files.hasNext()) {
    
    var file = files.next();
    console.log(file.getName());

    if (file.getName() == fileName) {
     return file; 
    }
  }

【讨论】:

  • 感谢罗恩的提示。我的问题是 DriveApp 服务停止工作。
猜你喜欢
  • 2013-03-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-03-05
  • 2015-07-10
  • 1970-01-01
  • 1970-01-01
  • 2020-02-03
相关资源
最近更新 更多