英文:
Google Cloud API Speech-to-text Go program returns "Provided scope(s) are not authorized" when nodejs succeeds
问题
我正在使用Go库调用语音转文本API,如https://cloud.google.com/speech-to-text/docs/libraries#client-libraries-usage-go中所述。我已经创建了一个新的服务工作者,并给予它所有者角色,并设置了环境变量GOOGLE_APPLICATION_CREDENTIALS指向凭据文件。然而,当调用Recognize()
函数时,返回了一个错误:
2021/07/09 16:58:02 failed to recognize: rpc error: code = PermissionDenied desc = Provided scope(s) are not authorized
作为一个健全性检查,我可以将该文档页面中的Node库代码复制粘贴到一个新的Node脚本中,将GOOGLE_APPLICATION_CREDENTIALS变量设置为相同的凭据文件,测试代码可以正常运行:
$ node quickstart.js
Transcription: how old is the Brooklyn Bridge
所以基本的Node.js客户端示例代码可以正常工作,但是Go示例代码不行。
我尝试使用相同的Go项目使用存储API,并发现我可以枚举存储桶,获取对象的属性,并成功上传文件,使用相同的服务工作者凭据,所以我确定它能够找到凭据。
如果我进入调用中,在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
)
我该如何调查这个范围错误?
英文:
I'm starting with the Go libraries calling the Speech-to-Text API as described in https://cloud.google.com/speech-to-text/docs/libraries#client-libraries-usage-go .. I've created a new Service Worker, given it Owner role, and set the environment variable GOOGLE_APPLICATION_CREDENTIALS to point to the credentials file. However when it calls the Recognize()
function an Error is returned:
2021/07/09 16:58:02 failed to recognize: rpc error: code = PermissionDenied desc = Provided scope(s) are not authorized
As a sanity check, I can copy-paste the Node library code from that docs page into a fresh node script, set the GOOGLE_APPLICATION_CREDENTIALS variable to the same credentials file, and the test code runs OK:
$ node quickstart.js
Transcription: how old is the Brooklyn Bridge
So the very basic Nodejs client sample code works fine, but the Go sample code does not.
I've tried the storage API using the same Go project, and find I can enumerate storage buckets, get Attrs on Objects, and upload files OK, using the same service worker credentials, so I am sure it's finding the credentials.
If I step into the calls, inside NewClient()
I can see it's calling into defaultGRPCClientOptions
and internaloption.WithDefaultScopes(DefaultAuthScopes()...),
to set setting the scope "https://www.googleapis.com/auth/cloud-platform" which I think is all correct.
I'm running go 1.16.5, my go.mod
has:
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
)
What can I do to investigate this scopes error?
答案1
得分: 2
我们刚刚遇到了这个问题,并看到了你的帖子。似乎新版本 cloud.google.com/go/storage v1.16.0 // indirect
是问题所在。我们强制使用了1.15.0版本,它对我们来说是可行的,并且仍然有效。我们一直以为这是一个权限问题,也许是因为他们改变了所需的内容。我建议你强制使用v1.15.0版本,看看是否能解决你的问题。
英文:
we ran into this just now and saw your post. It seems the new version cloud.google.com/go/storage v1.16.0 // indirect
is the problem. we forced 1.15.0 which was working for us and it continues to work. we were going nuts thinking it was a permission problem. Maybe it is if they changed what's required. I would force v1.15.0 and see if that fixes it for you.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论