dry9192 2019-09-06 00:51
浏览 55

如何通过Golang获取gcp承载令牌

1.I'm try to use google translation api V3beta1 to translate words, I use http post to send request, but how to get bearer token by golang? 2.Or if I use grpc protocol, whether can I don't pass the bearer token. and where can I get the v3beta1 grpc interface file.

I test translate v2 rest api, it's ok whitout bearer token,but it return 401 code when I use v3beta1 api, I notice there is a bearer token need to pass, but I don't how to get it with golang.

//code such here
headMap := &http.Header{}
    headMap.Add("Content-Type", "application/json")
    headMap.Add("Accept", "application/json")
    //headMap.Add("Authorization", "Bearer (how to get this bear)")
    bodyParams := goov3Req{
        Content: "你好",
        SourceLanguageCode:"zh",
        TargetLanguageCode:"en",
        //MimeType:"text",
        Model:"nmt",
        //Key:googleRestFulKey,
    }
    fmt.Println(bodyParams)

    str, _ := json.Marshal(bodyParams)

    var b []byte
    var e error

    _, b, _, e = util.DoPost("google_its", googleRestFulUrl, *headMap, []byte(str), timeout)

"error": {


----------

//get error code
    "code": 401,
    "message": "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
    "status": "UNAUTHENTICATED"
  }
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 素材场景中光线烘焙后灯光失效
    • ¥15 请教一下各位,为什么我这个没有实现模拟点击
    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 保护模式-系统加载-段寄存器