Google Action 推送通知请求上的 403

Irw*_*win 5 jwt actions-on-google

我正在尝试为 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");
Run Code Online (Sandbox Code Playgroud)

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

小智 -1

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

\n\n
    \n
  1. 检查您的 Google 权限设置\n为了测试该操作,您需要启用必要的权限。
  2. \n
\n\n

转至 \xe2\x80\x98活动控制页面 ( https://myaccount.google.com/activitycontrols )。\n使用您的 Google 帐户登录(如果您尚未登录)。\n请确保具有以下权限已启用:

\n\n
a.Web & App Activity\nb.Device Information\nc.Voice & Audio Activity\n
Run Code Online (Sandbox Code Playgroud)\n\n

2.应将目标意图名称添加到隐式调用字段中。\n启用推送通知。\n3.在 Google 助理中使用与在GCP中登录时使用的相同电子邮件 ID 。

\n