使用 Deployment Manager 在 BigQuery 中创建“外部表”时,“获取云端硬盘凭据时出现 403 权限被拒绝”

Mou*_*ess 5 google-drive-api google-bigquery google-cloud-platform google-deployment-manager

重现步骤:

  • 在 Google 表格中创建工作表
  • 在 Google Cloud Platform 中启用 Deployment Manager 和 Google Drive API
  • view添加具有工作表权限的部署管理器服务帐户
  • 使用部署管理器创建数据集
  • 使用 Deployment Manager 创建表,在 sourceUris 中引用外部表
部分Python模板:
def GenerateConfig(context):
    name: str = context.env['name']
    dataset: str = context.properties['dataset']
    tables: [] = context.properties['tables']
    location: str = context.properties.get('location', 'EU')
    resources = [{
        'name': name,
        'type': 'gcp-types/bigquery-v2:datasets',
        'properties': {
            'datasetReference': {
                'datasetId': dataset,
            },
            'location': location
        },
    }]

    for t in tables:
        resources.append({
            'name': '{}-tbl'.format(t["name"]),
            'type': 'gcp-types/bigquery-v2:tables',
            'properties': {
                'datasetId': dataset,
                'tableReference': {
                    'tableId': t["name"]
                },
                'externalDataConfiguration': {
                    'sourceUris': ['https://docs.google.com/spreadsheets/d/123123123123123-123123123123/edit?usp=sharing'],
                    'sourceFormat': 'GOOGLE_SHEETS',
                    'autodetect': True,
                    'googleSheetsOptions':
                        {
                            "skipLeadingRows": '1',
                        }
                }
            },
        })
    return {'resources': resources}
Run Code Online (Sandbox Code Playgroud)

我发现了一些诸如此类的线索但它们都引用了使用“范围”来添加https://www.googleapis.com/auth/drive。我不确定如何将范围添加到部署管理器请求,或者范围实际上是如何工作的。

任何帮助,将不胜感激。

小智 1

是的,使用范围可以解决这个问题。但是,即使添加范围后,我也遇到了同样的错误。与 GCP 服务帐户共享 Google Sheets 文档帮助我摆脱了这个错误。

总结一下 - 使用范围并与您将用于查询表的 GCP 服务帐户共享文档。

另外,该文档对于查询外部表很有帮助