Google Cloud Vision APIへのAPI呼び出しを、GolangのAPIキーを使用して実行しようとしています。しかし、私は400: bad request, invalid_grant error
を得ています。Google CloudクライアントライブラリでAPIキーベースのREST呼び出しを行う方法
以下のコードのapiKey/apiKeyOption部分は私のものです。
この呼び出しを行う正しい方法は何ですか。まったく可能ですか?
import (
// ...
"google.golang.org/api/option"
vision "cloud.google.com/go/vision/apiv1"
"golang.org/x/net/context"
)
func getImageLabels(filename string) []string {
ctx := context.Background()
apiKey := "..." // I have a valid api key generated in the console.
apiKeyOption := option.WithAPIKey(apiKey)
client, err := vision.NewImageAnnotatorClient(ctx, apiKeyOption)
// ...
labels, err := client.DetectLabels(ctx, image, nil, 10)
}
...
Failed to detect labels: rpc error: code = Internal desc = transport: oauth2: cannot fetch token: 400 Bad Request
Response: {
"error" : "invalid_grant"
}
は、私は今、通常のREST呼び出しとしてクライアントライブラリなしでこれを実装しました。しかし、それがクライアントライブラリで可能かどうかを知ることはまだ興味があります。 – sathishvj