【发布时间】:2018-05-15 16:25:29
【问题描述】:
我尝试使用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 旁边我们有绿色箭头来运行方法。
【问题讨论】:
-
你能展示你的导出命令以及你是如何运行代码的吗?
-
请分享
stat $GOOGLE_APPLICATION_CREDENTIALS的输出 -
"但是当我重新启动计算机并调用 stat 时,我有 stat: missing operand" - 这表明您只确保环境变量存在于当前会话中。目前尚不清楚“当我开始编写代码时”是什么意思——我们不知道你是如何运行代码的。如果在同一个会话中应该没问题,否则环境变量就不存在了。
-
我在 IDE 中运行代码,并在我导出的同一会话中运行它。
-
我没有设置 $GOOGLE_APPLICATION_CREDENTIALS,但我有相同的结果使用方法:github.com/GoogleCloudPlatform/java-docs-samples/issues/697(最后一个)
标签: java google-api google-authentication