java - GOOGLE_APPLICATION_CREDENTIALS 在 JAVA 中不起作用

标签 java google-api google-authentication

我尝试使用 Google Speach Api

我在身份验证方面遇到了大问题。

我关注了这个tutorial ,然后导出 GOOGLE_APPLICATION_CREDENTIALS,并使用 echo 检查它,一切正常。

但是当我从第一个链接开始编写代码时出现错误:

Exception in thread "main" java.io.IOException: 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.
at com.google.auth.oauth2.DefaultCredentialsProvider.getDefaultCredentials(DefaultCredentialsProvider.java:119)
at com.google.auth.oauth2.GoogleCredentials.getApplicationDefault(GoogleCredentials.java:127)
at com.google.auth.oauth2.GoogleCredentials.getApplicationDefault(GoogleCredentials.java:100)
at com.google.api.gax.core.GoogleCredentialsProvider.getCredentials(GoogleCredentialsProvider.java:53)
at com.google.api.gax.rpc.ClientContext.create(ClientContext.java:110)
at com.google.cloud.speech.v1.stub.GrpcSpeechStub.create(GrpcSpeechStub.java:93)
at com.google.cloud.speech.v1.SpeechSettings.createStub(SpeechSettings.java:128)
at com.google.cloud.speech.v1.SpeechClient.<init>(SpeechClient.java:143)
at com.google.cloud.speech.v1.SpeechClient.create(SpeechClient.java:125)
at com.google.cloud.speech.v1.SpeechClient.create(SpeechClient.java:117)
at com.example.speech.QuickstartSample.main(QuickstartSample.java:58)

当然我检查了环境变量中的路径,即使我得到这个文件 chmod 777,也没有任何帮助。

有人遇到过类似的问题吗?

stat $GOOGLE_APPLICATION_CREDENTIALS 的输出:

File: /home/kruczek/Pulpit/mirthconnection-59cb32bcd531.json
Size: 2329          Blocks: 8          IO Block: 4096   regular file
Device: 801h/2049d  Inode: 2360629     Links: 1
Access: (0777/-rwxrwxrwx)  Uid: ( 1000/ kruczek)   Gid: ( 1000/ kruczek)
Access: 2017-12-01 14:20:33.111439885 +0100
Modify: 2017-12-01 14:20:33.111439885 +0100
Change: 2017-12-01 15:24:26.476545027 +0100
Birth: -

但是当我重新启动计算机并调用 stat 时,我有 stat: missing operand

我的导出推荐 export GOOGLE_APPLICATION_CREDENTIALS=/home/kruczek/Pulpit/mirthconnection-59cb32bcd531.json 我通过 IDE Intellij 运行项目,在 privat static void main 旁边我们有绿色箭头来运行方法。

最佳答案

在 eclipse 中, 运行 -> 运行配置.. -> 环境选项卡

在名称下输入 GOOGLE_APPLICATION_CREDENTIALS: 在Value中输入json路径:

请确保在值中输入路径时没有输入引号。

关于java - GOOGLE_APPLICATION_CREDENTIALS 在 JAVA 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47595514/

相关文章:

java - 使用 JDBC 可调用语句从 Java 调用的 Oracle 存储过程中绑定(bind)参数的顺序不正确

java - 如何从另一个类 Java Swing 调用方法?

java - 从 2000 行文件中提取数据的 Java XML 解析器(在移动设备上)

google-api - 测试 Google 的 ClientLogin

c# - 如何在 C#.Net 中实现 Google Place API

java - 从文本数据库检索图像并显示在按钮上

javascript - 如何基于 Google Books API 表示和自动完成建议的 JSON?

google-cloud-endpoints - 使用 Google 登录网站,是否可以通过编程方式登录?

javascript - 为什么 Django 中的 Google-Auth(Google Identity) 空白弹出窗口?

javascript - Angular 服务不作为exp工作