android - io.grpc.StatusRuntimeException: UNAUTHENTICATED: 凭证需要具有 PRIVACY_AND_INTEGRIY 的通道
问题描述
我在我的 android 应用程序中使用 Dialogflow Java 客户端库来运行下面链接中给出的检测意图 API。
我稍微修改了上面链接中给出的代码,以便在发送检测意图请求之前先对客户端进行身份验证。我的示例代码如下:
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 的安全级别?
解决方案
尝试更新您正在使用的库版本。应在传输层设置安全级别。
例如,我的 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")
}
推荐阅读
- jquery - 遍历 tr 结构并尝试创建一个数组列表
- python-sphinx - 如何配置 sphinx 以使用本地 mathjax
- mule - 第三方休息服务从 mule 流返回 503
- uber-api - 优步促销代码:预期用户体验
- python-2.7 - 通过使用 python 保持格式从 New 更新旧的 excel
- mysql - 根据其在mySql中的当前状态选择id
- python - Spyder 中的精美 python 文档
- sql - 尝试通过 Oracle 数据库中的 bash 脚本将数据从暂存表插入另一个表时违反唯一约束
- qt - 从 QTableWidget 复制数据
- java - 如何获取 Office 文档的子类型 MIME,而不是在 Tika 中获取 OOXML