登录
首页 >  Golang >  Go问答

Google Cloud API 语音转文本 Go 程序返回“未授权提供的范围”当 nodejs 成功运行时

来源:stackoverflow

时间:2024-02-14 21:09:23 249浏览 收藏

本篇文章给大家分享《Google Cloud API 语音转文本 Go 程序返回“未授权提供的范围”当 nodejs 成功运行时》,覆盖了Golang的常见基础知识,其实一个语言的全部知识点一篇文章是不可能说完的,但希望通过这些问题,让读者对自己的掌握程度有一定的认识(B 数),从而弥补自己的不足,更好的掌握它。

问题内容

我从调用 speech-to-text api 的 go 库开始,如 https://cloud.google.com/speech-to-text/docs/libraries#client-libraries-usage-go 中所述。我创建了一个新的 service worker,赋予它 owner 角色,并将环境变量 google_application_credentials 设置为指向凭据文件。但是,当它调用 recognize() 函数时,会返回错误:

2021/07/09 16:58:02 failed to recognize: rpc error: code = permissiondenied desc = provided scope(s) are not authorized

作为完整性检查,我可以将该文档页面中的节点库代码复制粘贴到新的节点脚本中,将 google_application_credentials 变量设置为相同的凭据文件,并且测试代码运行正常:

$ node quickstart.js
transcription: how old is the brooklyn bridge

因此,非常基本的 nodejs 客户端示例代码可以正常工作,但 go 示例代码却不能。

我已经尝试使用相同的 go 项目的存储 api,发现我可以使用相同的服务工作人员凭据枚举存储桶、获取对象的 attr 并上传文件,因此我确信它正在找到凭据。

如果我进入调用,在 newclient() 内部,我可以看到它正在调用 defaultgrpcclientoptionsinternaloption.withdefaultscopes(defaultauthscopes()...), 来设置范围“https://www.googleapis. com/auth/cloud-platform”,我认为这是完全正确的。

我正在运行 go 1.16.5,我的 go.mod 有:

require (
    cloud.google.com/go v0.86.0 // indirect
    cloud.google.com/go/storage v1.16.0 // indirect
    firebase.google.com/go/v4 v4.6.0 // indirect
    github.com/boj/redistore v0.0.0-20180917114910-cd5dcc76aeff // indirect
    github.com/gin-gonic/contrib v0.0.0-20201101042839-6a891bf89f19 // indirect
    github.com/gin-gonic/gin v1.7.2 // indirect
    github.com/golang/gddo v0.0.0-20210115222349-20d68f94ee1f // indirect
    github.com/gorilla/mux v1.8.0 // indirect
    github.com/gorilla/sessions v1.2.1 // indirect
    github.com/mattn/go-isatty v0.0.12 // indirect
    github.com/sirupsen/logrus v1.8.1 // indirect
    golang.org/x/oauth2 v0.0.0-20210628180205-a41e5a781914 // indirect
    google.golang.org/api v0.50.0 // indirect
    google.golang.org/genproto v0.0.0-20210708141623-e76da96a951f // indirect
    google.golang.org/protobuf v1.27.1 // indirect
)

我该如何调查此范围错误?


正确答案


我们刚刚遇到了这个问题并看到了您的帖子。看来新版本 cloud.google.com/go/storage v1.16.0 //indirect 是问题所在。我们强制使用了 1.15.0,它对我们有效并且继续有效。我们简直要疯了,以为这是一个许可问题。如果他们改变了要求,也许是这样。我会强制使用 v1.15.0,看看是否可以解决该问题。

今天关于《Google Cloud API 语音转文本 Go 程序返回“未授权提供的范围”当 nodejs 成功运行时》的内容就介绍到这里了,是不是学起来一目了然!想要了解更多关于的内容请关注golang学习网公众号!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>