You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用OneSignal发送通知时遭遇403 Access Denied错误求助

排查OneSignal 403权限拒绝问题

以下是针对你遇到的403错误的具体排查和修复点:

  • 密钥类型误用
    你当前使用的User Auth Key是账户级操作凭证(用于管理应用、账户设置等),而发送通知需要的是目标应用专属的REST API Key。这个密钥可在OneSignal控制台的目标应用详情页 → Settings → Keys & IDs下找到,替换掉Authorization头中的现有密钥即可。

  • 认证头格式校验
    确认Authorization头的格式为Basic <你的应用REST API Key>,注意Basic与密钥之间必须有一个空格,且密钥不要包含多余的引号或空格。

  • 请求参数错误(附带修复)
    你的代码中include_player_ids字段值写为"Subscribed Users"是错误的:

    • 若要给所有订阅用户发送通知,应改用included_segments: ["Subscribed Users"]
    • 若指定特定用户,include_player_ids需传入player_id数组,例如include_player_ids: ["player_id_1", "player_id_2"]

修正后的示例代码:

const response = await fetch('https://api.onesignal.com/notifications', {
  method: 'POST',
  headers: {
    'accept': 'application/json',
    'Content-Type': 'application/json',
    Authorization: 'Basic <你的应用REST API Key>',
  },
  body: JSON.stringify({
    app_id: "<你的应用ID>", 
    contents: { en: data.report_title },
    included_segments: ["Subscribed Users"],
    headings: { en: 'New Notification' }, 
  }),
})

内容的提问来源于stack exchange,提问作者Robert

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.16 14:52:02