1。我正在尝试使用Google翻译API V3beta1来翻译单词,我使用http发布来发送请求,但是如何通过golang获取不记名令牌? 2.或者如果我使用grpc协议,是否不能传递不记名令牌。在哪里可以找到v3beta1 grpc接口文件。
我测试了v2 rest api的翻译,它是可以的,没有承载令牌,但是当我使用v3beta1 api时它返回401代码,我注意到有一个承载令牌需要传递,但是我不知道如何用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"
}