【发布时间】:2019-12-10 18:26:27
【问题描述】:
我在我的项目中安装了google/cloud/translate,Gemfile.lock 中的版本是:
google-cloud-translate (2.1.0)
使用以下代码:
require "google/cloud/translate"
project_id = "<Project ID>" # from my Google Cloud Platform
translate = Google::Cloud::Translate.new version: :v2, project_id: project_id
这就是documentation 所说的以及这个answer 相关的建议(请注意我使用的是v2 而不是v3)
RuntimeError: Could not load the default credentials. Browse to
https://developers.google.com/accounts/docs/application-default-credentials for more information
这部分返回true:
require "google/cloud/translate"
更新 我已经按照以下所有步骤操作:
https://cloud.google.com/docs/authentication/production
创建了一个服务帐户、一个凭据密钥并设置了 env 变量(在 Windows 上),然后我尝试使用 google/cloud/storage 示例测试凭据配置,它工作正常,但是当我尝试使用:google/cloud/translate gem 时
translate = Google::Cloud::Translate.new version: :v2, project_id: project_id
我还是遇到了同样的错误
可能是什么错误? 提前感谢您的帮助。
【问题讨论】:
-
你没看developers.google.com/accounts/docs/…吗?它告诉你去那个页面找出它为什么不起作用。当您转到该页面时,它提供了多个示例,说明如何将您的凭据加载到您的应用程序中,包括
export GOOGLE_APPLICATION_CREDENTIALS。该页面上甚至还有 Ruby 代码示例来展示如何做到这一点。我在这里错过了什么?
标签: ruby-on-rails ruby google-api google-translate google-cloud-translate