OneSignal删除通知。

3
我尝试使用REST API取消我通过API(使用include_player_ids和单个收件人)发送给单个用户的挂起通知,但是我不能在没有传递REST API KEY的情况下执行此操作,这不应该发生,因为在手册中它说在我发送的条件下是不必要的。
我做错了什么,还是OneSignal的服务出了问题?以下是代码:
//Creates the notification
$.post(
    "https://onesignal.com/api/v1/notifications",
    {
        "app_id": appId,
        "include_player_ids": [userId],
        "send_after": later,
        "template_id": templateId
    },
    function(data){
        localStorage.ni = data.id;
    }
);

//Cancel the notification
var notificationId = localStorage.ni;
$.get("https://onesignal.com/api/v1/notifications/"+notificationId+"?app_id="+appId);

这是取消请求的响应结果:
{
    "errors":
        [
            "Please include a case-sensitive header of Authorization: Basic <YOUR-REST-API-KEY-HERE> with a valid REST API key."
        ],
    "reference":
        [
            "https://documentation.onesignal.com/docs/accounts-and-keys#section-keys-ids"
        ]
}
1个回答

1
答案比我想象的要简单。为了排除通知,我不能使用 $.get(),我必须明确表示我想删除它们。
因此,这个方法很好用:
$.ajax({
    url: "https://onesignal.com/api/v1/notifications/"+notificationId+"?app_id="+appId,
    type: "DELETE"
});

如何在一次请求中删除多个通知?例如,ID001、ID002、ID003? - Bruno Freire
除了设置“canceled”属性以取消通知外,它实际上并没有删除通知。通知仍然保留在完整的通知列表中。 - Sámal Rasmussen

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接