go - 当 nodejs 成功时,Google Cloud API Speech-to-text Go 程序返回“提供的范围未授权”
问题描述
我从调用 Speech-to-Text API 的 Go 库开始,如https://cloud.google.com/speech-to-text/docs/libraries#client-libraries-usage-go中所述。我我们创建了一个新的 Service Worker,赋予它所有者角色,并将环境变量 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,发现我可以使用相同的服务工作者凭据枚举存储桶、获取对象上的 Attrs 并上传文件,所以我确信它正在找到凭据。
如果我进入通话,在里面NewClient()
我可以看到它正在调用defaultGRPCClientOptions
并internaloption.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,看看是否可以为您解决问题。
推荐阅读
- python - NameError:名称“排序”未定义
- javascript - javascript原型由不同类型编写
- dart - 当我第一次渲染大图像时,颤动会等待很长时间。
- assembly - 如何解释二进制文件的转储?
- servicestack - servicestack 插件到将提供静态文件的 Windows 服务?
- winforms - 从资源中清除以前在 WinForm 中加载的图像
- linux - SublimeText3 通过 SSH 在服务器上构建
- javascript - fluent-ffmpeg:创建后无法删除视频截图
- ios - 带有 UIScrollView 的渐变背景色
- node.js - 使用不记名令牌请求 API 节点 js