我正在尝试使用Golang中的API密钥对Google Cloud Vision API进行API调用。但是我得到一个400: bad request, invalid_grant error
。
以下代码的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"
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句