actions-on-google - 谷歌智能家居第三方后台调用首页图错误
问题描述
我在做测试套件。参考测试套件流程图图片。开发者云可以接收谷歌助手发送的指令。但是当我向 homegraph 报告状态时,我得到了这个例外。我不知道为什么?
我参考这个网站https://developers.google.com/assistant/smarthome/develop/request-sync步骤。启用 Google homegraph API,创建服务帐户密钥,最后调用 API。
private void onDeviceAdded() throws IOException {
FileInputStream stream = new FileInputStream("service-account-key.json");
GoogleCredentials credentials = GoogleCredentials.fromStream(stream);
mySmartHomeApp.setCredentials(credentials);
RequestSyncDevicesResponse response = mySmartHomeApp.requestSync("my-self-user-id");
}
我得到的例外:
io.grpc.StatusRuntimeException: UNAVAILABLE: io exception
at io.grpc.stub.ClientCalls.toStatusRuntimeException(ClientCalls.java:233)
at io.grpc.stub.ClientCalls.getUnchecked(ClientCalls.java:214)
at io.grpc.stub.ClientCalls.blockingUnaryCall(ClientCalls.java:139)
at com.google.home.graph.v1.HomeGraphApiServiceGrpc$HomeGraphApiServiceBlockingStub.requestSyncDevices(HomeGraphApiServiceGrpc.java:406)
解决方案
您的服务调用 API 的方式似乎存在问题。
您可能希望查看直接从您的应用程序调用 gRPC 方法,并确保您拥有正确的 agentUserId 和服务帐户密钥。
库调用的实现粘贴在下面:
val channel = ManagedChannelBuilder.forTarget("homegraph.googleapis.com").build()
val blockingStub = HomeGraphApiServiceGrpc.newBlockingStub(channel)
// See https://grpc.io/docs/guides/auth.html#authenticate-with-google-3.
.withCallCredentials(MoreCallCredentials.from(this.credentials))
val request = HomeGraphApiServiceProto.RequestSyncDevicesRequest.newBuilder()
.setAgentUserId(agentUserId)
.build()
return blockingStub.requestSyncDevices(request)
推荐阅读
- sql-server - Linux 上的间歇性 SQL Server 连接问题
- php - 在 PHP 中用正则表达式替换字符串的一部分
- python-3.x - 如何从s3中的文件夹中读取所有镶木地板文件到熊猫
- c# - 非空运算符赋值
- html - 删除列之间的空白水平空间(Reactstrap、Bootrap、React)
- javascript - puppeteer userdatadir 浏览器崩溃
- javascript - 循环并检查对象 TS/JS 的类型
- kodi - 如何在根上为 Kodi 挂载磁盘
- elasticsearch - logstash 文件插件无响应
- android - 我的导航栏没有在 Android Studio Kotlin 中的片段之间切换