Javascript OneSignal删除通知
我试图使用REST API取消一个挂起的通知,该通知是我发送给一个同样使用该API的用户(使用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",
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"
});