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
    
    评论

报告相同问题?

悬赏问题

  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划