【问题标题】:Credentials Error when integrating Google Drive with与 Google Drive 集成时出现凭据错误
【发布时间】:2016-05-23 01:06:51
【问题描述】:

我正在使用 Google Big Query,我想将 Google Big Query 集成到 Google Drive。在大查询中,我提供了 Google 电子表格 url 来上传我的数据。它更新得很好,但是当我在 google Add-on(OWOX BI Big Query Reports)中编写查询时:

Select * from [datasetName.TableName]

我收到一个错误:

查询失败:tableUnavailable:找不到合适的凭据来访问 Google 云端硬盘。联系表所有者寻求帮助。

【问题讨论】:

  • 我只是给出基本的 sql 查询,例如 --
  • select * from [datasetname.tablename] ,在 google add-on(OWOX BI Big Query Reports) 中代码是正确的,但我得到一个错误——查询失败:tableUnavailable: 没有合适的凭据发现可以访问 Google Drive。联系表所有者寻求帮助。你能帮我解决一下,如何在console.cloud.google.com/apis/credentials中添加凭据
  • 这使用Federated Data Sources。在关注 these steps 并创建表时,系统会要求您允许 Google Drive View and manage 范围和 BigQuery View and manage 范围。如果您允许这些,那么 BigQuery 表是否正确创建?使用 Web UI 是否有任何错误?

标签: sql google-bigquery


【解决方案1】:

我刚刚在我正在编写的一些代码中遇到了同样的问题 - 它可能不会直接帮助你,因为看起来你不对代码负责,但它可能会帮助其他人,或者你可以问谁确实编写了您用来阅读此内容的代码:-)

所以我不得不做几件事:

  1. 除了 BigQuery 之外,还为我的 Google Cloud Platform 项目启用 Drive API。
  2. 确保您的 BigQuery 客户端是使用 BigQuery 范围和 Drive 范围创建的。
  3. 确保您希望 BigQuery 访问的 Google 表格与您的 Google Cloud Platform 将自己标识为的“...@appspot.gserviceaccount.com”帐户共享。

之后,我能够在我自己的项目中从 BigQuery 中成功查询 Google Sheets 支持的表。

【讨论】:

    【解决方案2】:

    前面说的是对的:

    1. 确保您在 BigQuery 中的数据集也与您将用于进行身份验证的服务帐号共享。
    2. 确保您的联合 Google 表格也与服务帐户共享。
    3. Drive Api 也应该处于活动状态
    4. 使用 OAuthClient 时,您需要同时为 Drive 和 BigQuery 注入作用域

    如果你正在编写 Python:

    1. credentials = GoogleCredentials.get_application_default()(不能注入作用域#我没找到方法:至少

    2. 从头开始构建您的请求:

      范围 = ( 'https://www.googleapis.com/auth/drive.readonly', 'https://www.googleapis.com/auth/cloud-platform')

      credentials = ServiceAccountCredentials.from_json_keyfile_name(
          '/client_secret.json', scopes)
      
      http = credentials.authorize(Http())
      
      bigquery_service = build('bigquery', 'v2', http=http)
      
      query_request = bigquery_service.jobs()
      query_data = {
          'query': (
              'SELECT * FROM [test.federated_sheet]')
      }
      
      query_response = query_request.query(
          projectId='hello_world_project',
          body=query_data).execute()
      
      print('Query Results:')
      for row in query_response['rows']:
          print('\t'.join(field['v'] for field in row['f']))
      

    【讨论】:

      【解决方案3】:

      这可能具有与以下相同的根本原因: BigQuery Credential Problems when Accessing Google Sheets Federated Table

      访问云端硬盘中的联合表需要额外的 OAuth 范围,并且您的工具可能只请求 bigquery 范围。尝试联系您的供应商以更新他们的应用程序?

      【讨论】:

        【解决方案4】:

        如果您像我一样使用 pd.read_gbq(),那么这将是获得答案的最佳位置:https://github.com/pydata/pandas-gbq/issues/161#issuecomment-433993166

        import pandas_gbq
        import pydata_google_auth
        import pydata_google_auth.cache
        
        # Instead of get_user_credentials(), you could do default(), but that may not
        # be able to get the right scopes if running on GCE or using credentials from
        # the gcloud command-line tool.
        credentials = pydata_google_auth.get_user_credentials(
            scopes=[
                'https://www.googleapis.com/auth/drive',
                'https://www.googleapis.com/auth/cloud-platform',
            ],
            # Use reauth to get new credentials if you haven't used the drive scope
            # before. You only have to do this once.
            credentials_cache=pydata_google_auth.cache.REAUTH,
            # Set auth_local_webserver to True to have a slightly more convienient
            # authorization flow. Note, this doesn't work if you're running from a
            # notebook on a remote sever, such as with Google Colab.
            auth_local_webserver=True,
        )
        
        sql = """SELECT state_name
        FROM `my_dataset.us_states_from_google_sheets`
        WHERE post_abbr LIKE 'W%'
        """
        
        df = pandas_gbq.read_gbq(
            sql,
            project_id='YOUR-PROJECT-ID',
            credentials=credentials,
            dialect='standard',
        )
        
        print(df)
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2019-07-25
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多