首页 > 解决方案 > io.grpc.StatusRuntimeException: UNAUTHENTICATED: 凭证需要具有 PRIVACY_AND_INTEGRIY 的通道

问题描述

我在我的 android 应用程序中使用 Dialogflow Java 客户端库来运行下面链接中给出的检测意图 API。

https://github.com/dialogflow/dialogflow-java-client-v2/blob/master/samples/src/main/java/com/example/dialogflow/DetectIntentTexts.java

我稍微修改了上面链接中给出的代码,以便在发送检测意图请求之前先对客户端进行身份验证。我的示例代码如下:

SessionsSettings sessionsSettings = SessionsSettings.newBuilder().setCredentialsProvider(credentialsProvider).build();
SessionsClient sessionsClient = SessionsClient.create(sessionsSettings);
SessionName session = SessionName.of(PROJECT_ID, sessionId);
                    System.out.println("Session Path: " + session.toString());
TextInput.Builder textInput = TextInput.newBuilder().setText(text).setLanguageCode(langCode);
QueryInput queryInput=QueryInput.newBuilder().setText(textInput).build();
DetectIntentResponse response = sessionsClient.detectIntent(session, queryInput);

在哪里

CredentialsProvider credentialsProvider = new CredentialsProvider() {
            @Override
            public Credentials getCredentials() throws IOException {
                InputStream fileStream = appContext.getApplicationContext().getAssets().open("MyDialogflowProject-4cxxxxx.json");
                return ServiceAccountCredentials.fromStream(fileStream);
            }
        };

但我收到以下错误

com.google.api.gax.rpc.UnauthenticatedException:io.grpc.StatusRuntimeException:UNAUTHENTICATED:凭据需要具有 PRIVACY_AND_INTEGRITY 安全级别的通道。观察到的安全级别:在 com.google.api.gax.rpc.ApiExceptionFactory.createException(ApiExceptionFactory.java:73) 处没有

谁能告诉在这种情况下如何设置 SessionSettings 的安全级别?

标签: androiddialogflow-es

解决方案


尝试更新您正在使用的库版本。应在传输层设置安全级别。

例如,我的 hello world 项目中的 gradle 依赖项正在使用 dialogflow v2:

dependencies { 
    compile ("com.google.api.grpc:proto-google-common-protos:1.12.0")
    compile ("io.grpc:grpc-netty:1.14.0")
    compile ("io.grpc:grpc-protobuf:1.14.0")
    compile ("io.grpc:grpc-stub:1.14.0")
    compile ("com.google.auth:google-auth-library-oauth2-http:0.10.0")
    compile ("com.google.cloud:google-cloud-storage:1.38.0")
    compile ("io.netty:netty-tcnative-boringssl-static:2.0.12.Final")
    compile ("com.google.cloud:google-cloud-dialogflow:0.55.1-alpha")

}


推荐阅读