2

我试图使用 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"
        ]
}
4

1 回答 1

1

答案比我想象的要容易。要排除通知,我不能使用$.get(),我必须明确地说我要删除它们。

所以,这很好用:

$.ajax({
    url: "https://onesignal.com/api/v1/notifications/"+notificationId+"?app_id="+appId,
    type: "DELETE"
});
于 2017-10-07T22:37:02.773 回答