[英]Trying to read/run query on bigquery from golang ad get Access Denied: BigQuery BigQuery: No OAuth token with Google Drive scope was found
I'm pretty new in golang and in google cloud.我在 golang 和谷歌云中很新。 I try to write the following code and get: (perform a simple query on big-query from golang) Error on read %v googleapi: Error 403: Access Denied: BigQuery BigQuery: No OAuth token with Google Drive scope was found., accessDenied I read few stackoverflow items about it, but can't find any information for golang.
我尝试编写以下代码并获得:(从 golang 对 big-query 执行简单查询)读取错误 %v googleapi: Error 403: Access Denied: BigQuery BigQuery: No OAuth token with Google Drive scope was found., accessDenied我阅读了一些关于它的 stackoverflow 项目,但找不到有关 golang 的任何信息。
my code:我的代码:
ctx := context.Background()
projectID := "XXXXXXXXX"
jsonPath:="XXXXX.json"
client, err := bigquery.NewClient(ctx, projectID,option.WithCredentialsFile(jsonPath))
if err != nil {
fmt.Println ("Failed to create client: %v", err)
return
}
destDatasetID:="dataset1"
destTableID:="table1"
q := client.Query("SELECT * from table1")
q.Location = "EU" // Location must match the dataset(s) referenced in query.
q.QueryConfig.Dst = client.Dataset(destDatasetID).Table(destTableID)
q.AllowLargeResults = true
fmt.Println("prepare complete")
it, err := q.Read(ctx)
if err != nil {
fmt.Println("Error on read %v",err)
return
}
code is ok, check your service account
access rights as: go to project console -> service accounts
代码没问题,请检查您的
service account
访问权限:转到项目控制台-> service accounts
-> create key along with
big query
access rights -> 创建密钥以及
big query
访问权限 -> finally create key and export is as
json
-> 最后创建密钥并导出为
json
few things to mention: 1. be conservative when giving access to service accounts (minimal access required) 2. re-name your keys in shell accordingly to avoid confusion ex: bigQueryReadOnly.json
需要提及的几件事:1. 在授予访问服务帐户的权限时要保守(需要最少的访问权限) 2. 相应地在 shell 中重命名您的密钥以避免混淆,例如:
bigQueryReadOnly.json
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.