I'm pretty new in golang and in google cloud. 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.
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
-> create key along with
big query
access rights -> finally create key and export is as
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