我有一个连接到 Google Sheet 的大型查询数据库,我在其中拥有只读访问权限 我的请求是,我想从表中获取数据,并且此请求在 Big Query 编辑器中运行得很好,但我想创建一个 Google Cloud 函数来拥有 API 并直接从 URL 访问此请求 我已经使用此命令创建了一个服务帐户:
gcloud iam service-accounts create connect-to-bigquery
gcloud projects add-iam-policy-binding test-24s --member="serviceAccount:[email protected]" --role="roles/owner"
我创建了一个 Google 云函数,如下所示: 创建云函数
这是我的 main.py 文件代码:
from google.cloud import bigquery
def hello_world(request):
client = bigquery.Client()
query = "SELECT order_id, MAX(status) AS last_status FROM `test-24s.Dataset.Order_Status` GROUP BY order_id"
query_job = client.query(query)
print("The query data:")
for row in query_job:
print("name={}, count ={}".format(row[0], row["last_status"]))
return f'The query run successfully'
对于requirements.txt 文件:
# Function dependencies, for example:
# package>=version
google-cloud-bigquery
该函数部署成功,但是当我尝试测试它时,出现此错误:
Error: function terminated. Recommended action: inspect logs for termination reason. Additional troubleshooting documentation can be found at https://cloud.google.com/functions/docs/troubleshooting#logging Details:
500 Internal Server Error: The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.
在阅读日志文件时我发现了这个错误
403 Access Denied: BigQuery BigQuery: Permission denied while getting Drive credentials.
请帮我解决这个问题,我已经尝试了在网上找到的所有解决方案,但没有成功
基于此:“获取云端硬盘凭据时权限被拒绝” - 我想说您的服务帐户的 IAM 权限不是“暂时的”=> 虽然该服务帐户可能具有对 BigQuery 的相关访问权限,但它无权访问下划线的内容电子表格保存在云端硬盘上...
我会尝试 - 要么
或者(最好从我的角度来看)
这个问题你解决了吗?我也有同样的问题?