【问题标题】:User-Id for Push-Notification on Actions for Google用于 Google 操作的推送通知的用户 ID
【发布时间】:2019-06-20 21:41:17
【问题描述】:

我尝试为我的 Google 助理应用程序制作推送通知。 我使用了谷歌开发者网站的 sendNotification 代码:https://developers.google.com/actions/assistant/updates/notifications

我正在编写 Java 代码。 一切正常,期待获得正确的用户 ID。 当我对我的用户进行硬编码时,它可以工作,但是如何在代码中获取用户 ID?

我尝试了以下代码:

Argument arg_userId = request.getArgument(ConstantsKt.ARG_UPDATES_USER_ID);

String userId = request.getUser().getUserId();

--> 我得到“java.lang.reflect.InvocationTargetException”

String userId = arg_userId.getRawText();

--> 相同的异常

【问题讨论】:

    标签: push-notification dialogflow-es actions-on-google google-api-java-client


    【解决方案1】:

    您获取通知 ID 的方法存在两个问题:

    1. 附加到用户对象的 ID 是 deprecated,可能不可用。
    2. 这不是您想要的 ID。

    在用户finalizes the notification 的响应中,该响应包含一个您应该获取并存储的ID。由于您使用的是 Java,因此代码可能如下所示:

    ResponseBuilder responseBuilder = getResponseBuilder(request);
    
    Argument permission = request.getArgument(ConstantsKt.ARG_PERMISSION);
    if (permission != null) {
      Argument userId = request.getArgument(ConstantsKt.ARG_UPDATES_USER_ID);
      // code to save intent and userID in your db
      responseBuilder.add("Ok, I'll start alerting you.").endConversation();
    } else {
      responseBuilder.add("Ok, I won't alert you.");
    }
    return responseBuilder.build();
    

    【讨论】:

    • 好吧,我不知道我怎么会错过...谢谢你,它现在可以工作了!
    • 很容易错过
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多