【问题标题】:403 on Google Action push notification requestGoogle Action 推送通知请求上的 403
【发布时间】:2019-04-26 05:24:11
【问题描述】:

我正在尝试为 Google Actions Intent 执行推送通知。

到目前为止,我已按照此处的说明进行操作:https://developers.google.com/actions/assistant/updates/notifications#send_notifications

这是我的结果代码:

const {google} = require('googleapis');
var request = require('request');

const key = require('./bot.json');

module.exports = async function (context, myQueueItem) {
    context.log('JavaScript queue trigger function processed work item', myQueueItem);

    let jwtClient = new google.auth.JWT(
        key.client_email, null, key.private_key,
       ['https://www.googleapis.com/auth/actions.fulfillment.conversation'],
        null
      );

      jwtClient.authorize((err, tokens) => {
        // code to retrieve target userId and intent
        let notif = {
          userNotification: {
            title: [message],
          },
          target: {
              userId:[obtained from permission request],
              intent: [name of intent],
            // Expects a IETF BCP-47 language code (i.e. en-US)
            locale: 'en-US'
          },
        };

        request.post('https://actions.googleapis.com/v2/conversations:send', {
          'auth': {
            'bearer': tokens.access_token,
           },
          'json': true,
          'body': {'customPushMessage': notif},
        }, (err, httpResponse, body) => {
            console.log(body);
           console.log(httpResponse.statusCode + ': ' + httpResponse.statusMessage);
        });
      });
};

//module.exports(console, "Test");

这会导致通知服务出现 403。这是因为生成的用户 ID、意图名称或 jwtoken 吗?

【问题讨论】:

  • 您是否在用户参与度中为您在操作控制台中的意图启用了您想发送推送通知吗?
  • 是的,我已在用户参与度中启用它。
  • 你总是得到 403 吗?发送通知时,每个用户每分钟限制 1 个通知。您收到任何错误消息吗?
  • 是的。 100% 失败
  • 您是否为您的项目启用了 Actions API?转到Google Cloud Platform console 以激活 Actions API,然后选择您在 Actions on Google 控制台上创建的项目。然后,单击启用按钮。

标签: jwt actions-on-google


【解决方案1】:

以下是我们在发送推送通知之前需要检查的步骤

  1. 检查您的 Google 权限设置 为了测试 Action,您需要启用必要的权限。

转到“活动控制”页面 (https://myaccount.google.com/activitycontrols)。 如果您尚未登录,请使用您的 Google 帐户登录。 确保启用以下权限:

a.Web & App Activity
b.Device Information
c.Voice & Audio Activity

2.目标意图名称应添加到隐式调用字段中。 启用推送通知。 3.在您的谷歌助手中使用您在 GCP 中登录时使用的相同电子邮件 ID。

【讨论】:

    猜你喜欢
    • 2017-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多