billing/quota_project
#GoogleCloud
課金プロジェクト
~/.config/gcloud/application_default_credentials.json では
$ gcloud auth application-default login した際に core/project から自動的に設定される?
$ gcloud auth application-default set-quota-project {PROJECT} で明に設定できる
無い場合一部の API が叩けない
? GCP 系はそのリソースのプロジェクトに、spreadsheet 等はエラーになる??
node のクライアントライブラリから明に指定するには今のところ gaxios の headers に指定するしかない
HTTP リクエストヘッダでは X-Goog-User-Project で渡す
システム パラメータ  |  Cloud APIs  |  Google Cloud
カレントプロジェクトを空にしたまま暮らしているが以下みたいに渡してあげないといけない
code:spreadsheet.js
const {google} = require('googleapis');
(async function () {
const auth = new google.auth.GoogleAuth({
scopes: 'https://www.googleapis.com/auth/spreadsheets.readonly',
projectId: "pokutuna-playground",
});
const sheets = google.sheets({
version: 'v4',
auth,
headers: { "X-Goog-User-Project": 'pokutuna-playground' }
});
const res = await sheets.spreadsheets.values.get({
spreadsheetId: '...',
range: '...',
});
console.log(res.data.values)
})()
Go の client は明に option.WithQuotaProject で渡せるな
code:spreadsheet.go
package main
import (
"context"
"fmt"
"log"
"google.golang.org/api/option"
"google.golang.org/api/sheets/v4"
)
func main() {
ctx := context.Background()
client, err := sheets.NewService(ctx, option.WithQuotaProject("pokutuna-playground"))
if err != nil {
log.Fatalf("Unable to retrieve Sheets client: %v", err)
}
spreadsheetId := "..."
resp, err := client.Spreadsheets.Values.Get(spreadsheetId, "...").Do()
if err != nil {
log.Fatalf("Unable to retrieve data from sheet: %v", err)
}
for _, row := range resp.Values {
for _, col := range row {
fmt.Printf("%s,", col)
}
fmt.Printf("\n")
}
}