gpt4 book ai didi

javascript - OneSignal 删除通知

转载 作者:行者123 更新时间:2023-12-05 06:38:21 25 4
gpt4 key购买 nike

我试图使用 REST API 取消我发送给也使用 API 的单个用户的未决通知(使用 include_player_ids 和单个收件人),但是如果没有传递 REST API KEY,这不应该发生,因为在 manual 中它说在我发送的条件下这是没有必要的。

是我做错了什么还是 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"
]
}

最佳答案

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

所以,这很好用:

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

关于javascript - OneSignal 删除通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46392603/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com