首页 > 解决方案 > 谷歌智能家居第三方后台调用首页图错误

问题描述

我在做测试套件。参考测试套件流程图图片。开发者云可以接收谷歌助手发送的指令。但是当我向 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)

我得到了例外

测试套件流程图

标签: actions-on-googlegoogle-smart-home

解决方案


您的服务调用 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)

推荐阅读