gpt4 book ai didi

android - 如何设置环境变量 GOOGLE_APPLICATION_CREDENTIALS?

转载 作者:行者123 更新时间:2023-11-29 18:55:17 35 4
gpt4 key购买 nike

我知道以前有人问过这种类型的问题,我已经解决了这个问题,但仍然面临这个问题。我用的是 this example .但是当我运行我的代码时,我遇到了以下异常

Failed to detect whether we are running on Google Compute Engine. java.net.ConnectException: Failed to connect to /169.254.169.254:80 at com.android.okhttp.internal.io.RealConnection.connectSocket(RealConnection.java:143) at com.android.okhttp.internal.io.RealConnection.connect(RealConnection.java:112) at com.android.okhttp.internal.http.StreamAllocation.findConnection(StreamAllocation.java:184) at com.android.okhttp.internal.http.StreamAllocation.findHealthyConnection(StreamAllocation.java:126) at com.android.okhttp.internal.http.StreamAllocation.newStream(StreamAllocation.java:95) at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:281) at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:224) at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:461) at com.android.okhttp.internal.huc.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:127) at com.google.api.client.http.javanet.NetHttpRequest.execute(NetHttpRequest.java:104) at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:981) at com.google.auth.oauth2.ComputeEngineCredentials.runningOnComputeEngine(ComputeEngineCredentials.java:191) at com.google.auth.oauth2.DefaultCredentialsProvider.tryGetComputeCredentials(DefaultCredentialsProvider.java:270) at com.google.auth.oauth2.DefaultCredentialsProvider.getDefaultCredentialsUnsynchronized(DefaultCredentialsProvider.java:194) at com.google.auth.oauth2.DefaultCredentialsProvider.getDefaultCredentials(DefaultCredentialsProvider.java:112) 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:134) at com.google.cloud.dialogflow.v2.stub.GrpcSessionsStub.create(GrpcSessionsStub.java:75) at com.google.cloud.dialogflow.v2.stub.SessionsStubSettings.createStub(SessionsStubSettings.java:100) at com.google.cloud.dialogflow.v2.SessionsClient.(SessionsClient.java:132) at com.google.cloud.dialogflow.v2.SessionsClient.create(SessionsClient.java:114) at com.google.cloud.dialogflow.v2.SessionsClient.create(SessionsClient.java:106) at com.example.lpt_0096.dialogflowv2.MainActivity$MyAsync.detectIntentStream(MainActivity.java:76) at com.example.lpt_0096.dialogflowv2.MainActivity$MyAsync.doInBackground(MainActivity.java:61) at android.os.AsyncTask$2.call(AsyncTask.java:333) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636) at java.lang.Thread.run(Thread.java:764) W/System.err: 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. W/System.err: at com.google.auth.oauth2.DefaultCredentialsProvider.getDefaultCredentials(DefaultCredentialsProvider.java:119) W/System.err: at com.google.auth.oauth2.GoogleCredentials.getApplicationDefault(GoogleCredentials.java:127) W/System.err: at com.google.auth.oauth2.GoogleCredentials.getApplicationDefault(GoogleCredentials.java:100) W/System.err: at com.google.api.gax.core.GoogleCredentialsProvider.getCredentials(GoogleCredentialsProvider.java:53) W/System.err: at com.google.api.gax.rpc.ClientContext.create(ClientContext.java:134) W/System.err: at com.google.cloud.dialogflow.v2.stub.GrpcSessionsStub.create(GrpcSessionsStub.java:75) W/System.err: at com.google.cloud.dialogflow.v2.stub.SessionsStubSettings.createStub(SessionsStubSettings.java:100) W/System.err: at com.google.cloud.dialogflow.v2.SessionsClient.(SessionsClient.java:132) W/System.err: at com.google.cloud.dialogflow.v2.SessionsClient.create(SessionsClient.java:114) W/System.err: at com.google.cloud.dialogflow.v2.SessionsClient.create(SessionsClient.java:106) W/System.err: at com.example.lpt_0096.dialogflowv2.MainActivity$MyAsync.detectIntentStream(MainActivity.java:76) W/System.err: at com.example.lpt_0096.dialogflowv2.MainActivity$MyAsync.doInBackground(MainActivity.java:61) W/System.err: at android.os.AsyncTask$2.call(AsyncTask.java:333) W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:266) W/System.err: at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245) W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162) W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636) W/System.err: at java.lang.Thread.run(Thread.java:764)

我是windows用户,android studio从哪里设置环境变量

最佳答案

来自错误

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.

您可能需要将此添加到环境变量路径 GOOGLE_APPLICATION_CREDENTIALS=path/to/your/service_accont_key_file.json。并且应该从这里获取 json 文件 https://cloud.google.com/docs/authentication/getting-started .此外,如果您不知道如何设置环境变量路径,您可以查看此 https://www.computerhope.com/issues/ch000549.htm

关于android - 如何设置环境变量 GOOGLE_APPLICATION_CREDENTIALS?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50019736/

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