gpt4 book ai didi

java - GOOGLE_APPLICATION_CREDENTIALS 在 JAVA 中不起作用

转载 作者:行者123 更新时间:2023-12-05 07:38:48 24 4
gpt4 key购买 nike

我尝试使用 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com