BigQuery AppsScript客户端的默认范围不包括Google云端硬盘

时间:2018-08-15 04:09:35

标签: google-apps-script google-drive-api google-cloud-platform google-bigquery

我一直在尝试通过Apps脚本中的API在BigQuery中将驱动器文件(工作表)设置为联合数据源。由于某些原因,从UI启用Drive API并没有真正起作用。我仍然会发现Drive范围丢失。

任何想法都会很有帮助。

1 个答案:

答案 0 :(得分:0)

好的,我刚刚解决了这个问题,这是万一您遇到此问题的方法。在用户界面中仅启用Drive API是不够的。

如果应用未在其他位置显式调用任何与Drive相关的API调用,则不会将驱动器作用域添加到脚本清单中。

在我的情况下,这可以通过在manifest.json文件中明确启用驱动器作用域来工作(请在UI中选择“显示清单文件”)。驱动器的作用域是https://www.googleapis.com/auth/drive,要添加到 oauthScopes 列表中,例如:

{
  "timeZone": "Asia/Dubai",
  "oauthScopes": [
    "https://www.googleapis.com/auth/drive",
    "https://www.googleapis.com/auth/bigquery",
    "https://www.googleapis.com/auth/spreadsheets"
  ],
  "dependencies": {
    "enabledAdvancedServices": [{
      "userSymbol": "Drive",
      "serviceId": "drive",
      "version": "v3"
    }, {
      "userSymbol": "BigQuery",
      "serviceId": "bigquery",
      "version": "v2"
    }]
  },
  "webapp": {
    "access": "MYSELF",
    "executeAs": "USER_DEPLOYING"
  },
  "exceptionLogging": "STACKDRIVER"
}