duanbarong4617 2018-12-08 09:00
浏览 34

如何解决“找不到默认凭据”错误

I'm making a program from this link on image detection but while calling a function it will give the error in main main function I call that function function which detect the image that what type of image Is. The program is given below:-

package main
import (
    "bufio"
    "bytes"
    "context"
    "fmt"
    "io"
    "os"

    vision "cloud.google.com/go/vision/apiv1"
)
func init() {
    _ = context.Background()
    _ = vision.ImageAnnotatorClient{}
    _ = os.Open
}
func detectFaces(w io.Writer, file string) error {
    ctx := context.Background()

    client, err := vision.NewImageAnnotatorClient(ctx)
    if err != nil {
        fmt.Println("Hello in function")
        return err
    }

    f, err := os.Open(file)
    if err != nil {
        return err
    }
    defer f.Close()

    image, err := vision.NewImageFromReader(f)
    if err != nil {
        return err
    }
    annotations, err := client.DetectFaces(ctx, image, nil, 10)
    if err != nil {
        return err
    }
    if len(annotations) == 0 {
        fmt.Fprintln(w, "No faces found.")
    } else {
        fmt.Fprintln(w, "Faces:")
        for i, annotation := range annotations {
            fmt.Fprintln(w, "  Face", i)
            fmt.Fprintln(w, "    Anger:", annotation.AngerLikelihood)
            fmt.Fprintln(w, "    Joy:", annotation.JoyLikelihood)
            fmt.Fprintln(w, "    Surprise:", annotation.SurpriseLikelihood)
        }
    }
    return nil
}
func main() {
    var b bytes.Buffer
    writer := bufio.NewWriter(&b)
    err := detectFaces(writer, "aaa.jpg")
    fmt.Println(err)
}

Error is:-

google: could not find default credentials. See https://developers.google.com/accounts/docs/application-default-credentials for more information.

How to solve this error. Can anyone Help me?

  • 写回答

1条回答 默认 最新

  • dongxixiu9134 2018-12-08 09:24
    关注

    Create a project with the Google Cloud Console, and enable the Vision API.

    From the Cloud Console, create a service account, download its json credentials file, then set the GOOGLE_APPLICATION_CREDENTIALS environment variable:

    export GOOGLE_APPLICATION_CREDENTIALS=/path/to/your-project-credentials.json
    
    评论

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法