我正在使用Google Big Query,我想将Google Big Query集成到Google云端硬盘。在Big查询中,我提供Google电子表格网址以上传我的数据它正在更新,但是当我在Google插件中编写查询时(OWOX BI Big Query Reports):
Select * from [datasetName.TableName]
我收到错误:
查询失败:tableUnavailable:找不到合适的凭据来访问Google云端硬盘。联系表所有者以获取帮助。
答案 0 :(得分:2)
我刚刚在我编写的一些代码中遇到了同样的问题 - 它可能不会直接帮助你,因为它看起来你不对代码负责,但它可能会帮助别人,或者你可以问那个人写下您正在使用的代码来阅读: - )
所以我必须做几件事:
之后,我能够在我自己的项目中成功查询来自BigQuery的Google表格支持的表格。
答案 1 :(得分:1)
之前所说的是对的:
如果您正在编写Python:
凭据= GoogleCredentials.get_application_default()(无法注入范围#I找不到方法:D至少
从头开始构建您的请求:
范围=( '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']))
答案 2 :(得分:0)
这可能与以下原因有着相同的根本原因: BigQuery Credential Problems when Accessing Google Sheets Federated Table
在Drive中访问联合表需要额外的OAuth范围,而您的工具可能只是请求bigquery范围。尝试联系您的供应商以更新其申请?
答案 3 :(得分:0)
如果您照常使用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)