无法设置Google API凭据 [英] Unable to set google api credentials
问题描述
我正在尝试按照这些说明在我的应用程序中使用google translation api ,但是在设置授权时遇到了一些麻烦。
I am trying to use the google translation api in my application by following these instructions, but having some trouble setting up the authorisation.
我创建了服务帐户,获取了json文件,并将其设置为
I created the service account, got the json file, and set it in with
set GOOGLE_APPLICATION_CREDENTIALS="C:\Users\Bassie\Documents\.credentials\google-translation-api\My Project-d885ebbbe907.json"
运行该命令后,我看不到任何输出,也看不到名为 GOOGLE_APPLICATION_CREDENTIALS <的系统环境变量/ code>(应该在哪里显示?)。
After running that command I don't see any output, and I don't see a system environment variable called GOOGLE_APPLICATION_CREDENTIALS
(is that where it should appear?).
当我尝试运行一些基本的示例代码时:
When I try running some basic sample code:
System.InvalidOperationException:'应用程序默认凭据不可用。如果它们在Google Compute Engine中运行,则可用。否则,必须定义环境变量GOOGLE_APPLICATION_CREDENTIALS,指向指向定义凭据的文件。请参见 https://developers.google.com/accounts/docs/application-default -凭据以获取更多信息。'
System.InvalidOperationException: 'The Application Default Credentials are not available. They are available if running in Google Compute Engine. Otherwise, the environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined pointing to a file defining the credentials. See https://developers.google.com/accounts/docs/application-default-credentials for more information.'
我在做什么错了?
更新
即使将值手动添加到系统环境变量后,我也遇到相同的错误。
even after manually adding the value to system environment variables, I get the same error.
推荐答案
您尝试过
echo %GOOGLE_APPLICATION_CREDENTIALS%
如果它不起作用,请右键单击我的计算机(或此PC)图标, ,在高级标签中,点击环境变量,在系统变量下添加一个新变量。
If it is not working, then right click on my computer(or This PC) icon, properties, in the advanced tab, click on Environment Variables, add a new variable under system variables.
然后检查 echo%GOOGLE_APPLICATION_CREDENTIALS%
在命令提示符下。
Then check echo %GOOGLE_APPLICATION_CREDENTIALS%
in command prompt.
这篇关于无法设置Google API凭据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!