1 回答
TA貢獻(xiàn)1856條經(jīng)驗 獲得超11個贊
我之前也遇到過這個問題以及 App Engine 到 G Suite 的集成。您需要使用服務(wù)帳戶密鑰。默認(rèn)的是不夠的(我相信是因為它沒有私鑰,但這可能是錯誤的)。
本質(zhì)上,您需要使用您的代碼上傳一個密鑰并使用它來獲取Client(而不是使用默認(rèn)密鑰):
func getOauthClient(serviceAccountKeyPath string) *http.Client {
ctx := context.Background()
data, err := ioutil.ReadFile(serviceAccountKeyPath)
if err != nil {
log.Fatal(err)
}
creds, err := google.CredentialsFromJSON(ctx, data, "https://www.googleapis.com/auth/spreadsheets.readonly")
if err != nil {
log.Fatal(err)
}
return oauth2.NewClient(ctx, creds.TokenSource)
}
- 1 回答
- 0 關(guān)注
- 168 瀏覽
添加回答
舉報
