Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/385.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript OneSignal删除通知_Javascript_Onesignal_Web Notifications - Fatal编程技术网

Javascript OneSignal删除通知

Javascript OneSignal删除通知,javascript,onesignal,web-notifications,Javascript,Onesignal,Web Notifications,我试图使用REST API取消一个挂起的通知,该通知是我发送给一个同样使用该API的用户(使用include\u player\u id和一个接收者)的,但是如果不传递REST API密钥,我就不能这样做,这是不应该发生的,因为在我发送的条件下,它说这是不必要的 我是做错了什么,还是OneSignal的服务有问题?代码如下: //Creates the notification $.post( "https://onesignal.com/api/v1/notifications",

我试图使用REST API取消一个挂起的通知,该通知是我发送给一个同样使用该API的用户(使用
include\u player\u id
和一个接收者)的,但是如果不传递REST API密钥,我就不能这样做,这是不应该发生的,因为在我发送的条件下,它说这是不必要的

我是做错了什么,还是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"
        ]
}
{
“错误”:
[
“请使用有效的REST API密钥包含Authorization:Basic的区分大小写的标头。”
],
“参考”:
[
"https://documentation.onesignal.com/docs/accounts-and-keys#section-密钥ID“
]
}

答案比我想象的要简单。要排除通知,我不能使用
$.get()
,我必须明确表示我要删除它们

因此,这很有效:

$.ajax({
    url: "https://onesignal.com/api/v1/notifications/"+notificationId+"?app_id="+appId,
    type: "DELETE"
});

答案比我想象的要简单。要排除通知,我不能使用
$.get()
,我必须明确表示我要删除它们

因此,这很有效:

$.ajax({
    url: "https://onesignal.com/api/v1/notifications/"+notificationId+"?app_id="+appId,
    type: "DELETE"
});