GOOGLE_APPLICATION_CREDENTIALS在JAVA中不起作用

时间:2017-12-01 14:26:49

标签: 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旁边我们有绿色箭头来运行方法。

1 个答案:

答案 0 :(得分:0)

在日食中, 运行->运行配置。->环境选项卡

在“名称”下输入GOOGLE_APPLICATION_CREDENTIALS: 在值中输入json路径:

在“值”中输入路径时,请确保未输入引号。