【问题标题】:The caller does not have permission. Actions API调用者没有权限。操作 API
【发布时间】:2021-10-07 14:54:09
【问题描述】:

我正在尝试在 Actions Builder 上构建一个向自身发送推送通知的机器人。我正确配置意图并获取推送令牌并实现文档(https://developers.google.com/assistant/engagement/notifications#exchange_the_key_for_an_access_token_and_send_a_notification)给出的代码。

这是我的代码:

action.handle('SendPushIntent', async (conv) => {
  const serviceAccount = require('./service-account.json');
  console.log(serviceAccount.client_email); // I verified that service account is the same here as my GCP account.
  let client = auth.fromJSON(serviceAccount);
  client.scopes = ['https://www.googleapis.com/auth/actions.fulfillment.conversation'];
  let notification = {
    userNotification: {
      title: 'Example',
      text: 'Body'
    },
    target: {
      userId: conv.user.params.pushToken, // The push token stored, I verified is not empty, null or undefined
      intent: 'PushReceptorIntent',
      locale: conv.user.locale,
    },
  };
  client.authorize((err, tokens) => {
    if (err) {
      throw new Error(`Auth error: ${err}`); // No error here
    }
    request.post('https://actions.googleapis.com/v2/conversations:send', {
      'auth': {
        'bearer': tokens.access_token,
      },
      'json': true,
      'body': {'customPushMessage': notification, 'isInSandbox': true},
    }, (err, httpResponse, body) => {
      if (err) {
        throw new Error(`API request error: ${err}`);
      }
      console.log(`${httpResponse.statusCode}: ` + `${httpResponse.statusMessage}`);
      console.log(JSON.stringify(body));
    });
  });
});

当我尝试发送推送时出现此错误 {"error":{"code":403,"message":"The caller does not have permission","status":"PERMISSION_DENIED"}}

我已经获得了具有所有者权限的服务帐户密钥并将其提供给我的代码,因为文档需要https://developers.google.com/assistant/engagement/notifications#get_a_service_account_key

这是 Actions API 的图表,只收到 403 作为响应。我不知道出了什么问题。

我已经做了以下步骤:

  • 禁用/启用操作 API
  • 生成服务帐号
  • 已验证服务帐户具有所有者权限

希望你能帮我解决这个问题!

10 月 8 日编辑

为我的服务帐户添加了 Cloud Asset Owner 权限。

【问题讨论】:

    标签: google-cloud-platform push-notification action


    【解决方案1】:

    返回消息“{"error":{"code":403,"message":"调用者没有权限","status":"PERMISSION_DENIED"}}"如果您无权导出资产或获取组织、项目或文件夹的历史记录。

    要解决此问题,请向您的项目、文件夹或组织管理员请求访问权限。根据您尝试导出或获取其历史记录的资产,您将需要以下角色之一或包含所需 Cloud Asset API 权限的其他角色:

    • cloudasset.viewer
    • cloudasset.owner

    请查看this document 以了解有关如何获取有关此问题的更多详细信息的信息。

    如果您想了解更多关于 Cloud Asset API 可用的访问控制选项,please follow this link.

    如果您想了解更多关于角色和权限的信息,please follow this link

    【讨论】:

    • 感谢您的帮助,我已经为我使用的服务帐户添加了 Cloud Asset Owner 权限,但仍然无法正常工作并得到相同的响应消息。我用我的项目权限主体列表的屏幕截图更新了帖子,显示了您引用的权限。
    • 也许你可以试试这个帖子中的答案,用户有类似的问题给你。有一个示例代码,可能对您的情况有用stackoverflow.com/questions/51821919/…
    • 最后是 Actions API 错误。我得到了他们的支持,现在一切都按预期进行!感谢您的帮助!
    猜你喜欢
    • 2022-07-13
    • 2021-04-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-08
    • 2017-04-04
    相关资源
    最近更新 更多