- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个移动应用程序需要使用 OneSignal API 通过 POST 接收通知。我在 Postman 上测试它,一切都很顺利。现在我想要做的是:获取一个 javaScript 片段并使用 OneSignal API 向我的手机发送任何推送通知。现在我正在尝试使用 w3Schools 上的示例来完成它,但它似乎不起作用。这就是我尝试这样做的方式:
<button type="button" onclick="loadDoc()">Request data</button>
<p id="demo"></p>
<script>
function loadDoc() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("demo").innerHTML = this.responseText;
}
};
xhttp.open("POST", "https://onesignal.com/api/v1/notification", true);
xhttp.setRequestHeader("Content-type", "application/json");
xhttp.setRequestHeader("Authorization", "Basic xxxxxxxxxxxxxxxxxx");
xhttp.send({
"app_id" : "xxxxxxxxxxxxxxxxxxxxxxxxxx",
"contents": {"en": "Hello World!"} ,
"included_segments" : ["All"]
});
}
</script>
</body>
</html>
我真的不明白我应该怎么做。
最佳答案
如今,Fetch API优于 XHR。它与浏览器一起提供,并且有轻量级的 polyfills。
const handleAsText = response => response.text();
const demo = document.getElementById("demo");
const displayResponse = responseText => demo.textContent = responseText;
function loadDoc() {
const method = "POST";
const headers = {
"Content-type": "application/json",
"Authorization": "Basic xxxxxxxxxxxxxxxxxx",
}
const body = JSON.stringify({
"app_id" : "xxxxxxxxxxxxxxxxxxxxxxxxxx",
"contents": {"en": "Hello World!"} ,
"included_segments" : ["All"],
})
return fetch("https://onesignal.com/api/v1/notification", {method, headers, body})
.then(handleAsText)
.then(displayResponse);
}
关于javascript - 向 OneSignal 推送通知发送 POST 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52453065/
使用 OneSignal (2.6.0) pod 成功安装,但它给出错误文件未在桥接头文件 xcode - 9.3,swift 4.1 中找到 最佳答案 从 github 存储库下载 OneSigna
我尝试通过 OneSignal 向 API REST 发送 API 通知,当我发送给一个唯一用户时它工作正常,但是当必须在 Json 中发送给多个用户时,通知会发送给唯一用户。 My JSON (li
当我从后端删除用户时,我还想从 OneSignal 数据库中删除该条目以保持我的数字和推送精确(对于 A/B 测试也很重要)。有没有办法做到这一点? 我搜索了 API,但似乎找不到任何可以删除条目的内
所以..我去使用服务器 api 更新我的播放器标签,所以我发送了 { "id": "someid", "tags":{"test1":"test2"}} 到这个信号 url(使用 python 和 g
Xcode 版本 7.3.1,我有开发者 apple id 嗨,我在工作和调试我的项目时遇到了奇怪的问题 错误提示:找不到 onesignal/onesignal.h 文件 我通过控制台安装和更新 p
我正在尝试在Android应用程序中设置OneSignal推送通知。我已经更改了build.gradle以包括所需的依赖关系(或者我认为)。 不管我做什么我都会得到 Failed to resolve
我已经打开了一个已经创建的项目。我正在添加Firebase和onesignal。已经添加了firebase,但是当我尝试添加此行时出现错误: implementation 'com.onesignal
我正在尝试在 Windows 系统上的两个 chrome(版本 20.0.1132.57)窗口之间创建对等连接。我将我的应用程序托管在 Linux 计算机上的 Node.js 服务器上并使用 sock
我正在使用 @nuxtjs/pwa 和 @nuxtjs/onesignal。我在安装时遇到 subscriptionChange 事件的监听器问题。它与 localhost 一起工作得很好,该问题发生
我制作了一个 ios 应用程序,并向我的应用程序添加了一个信号,我通过手机测试了我的应用程序,它运行良好,但我将我的应用程序上传到应用程序商店,通知不起作用。 onesignal 给我这个问题“One
我试图使用 REST API 取消我发送给也使用 API 的单个用户的未决通知(使用 include_player_ids 和单个收件人),但是如果没有传递 REST API KEY,这不应该发生,因
我需要为某些网站实现网络通知,并通过在控制台中执行的 php 脚本发送通知。 我发现通过使用这个库 https://github.com/web-push-libs/web-push-php 可以在不
我有这个应用程序,我想从我的管理面板发送推送通知。我认为我做的一切都很好,但是 OneSignal 仅在我将其安装在我的模拟器中时才会检测到我的应用程序已安装,但是当我在手机上安装 apk 时,它不会
我想在 oneSignal 中创建 Segments 而不必访问仪表板,所以我想知道他们是否有一个 API 用于或任何 和我一起做的其他方式 最佳答案 目前 OneSignal 没有任何用于创建段的
我想发送OneSignal的预定消息,但是我不想使用他们的仪表板,而是想使用API来做到这一点,我确实阅读了他们的文档,但是找不到任何可以修改其当前API的东西,所以我可以发送预定的通知 func
我对应用程序开发、Java 和 StackOverflow 完全陌生,这是我的第一个 Android 应用程序。 我已经实现了 OneSignal 来发送推送通知。我只是想在通知中添加对操作按钮的支持
我希望我的通知仅显示在通知栏中。当应用程序打开时,它将作为模式显示在屏幕上。 在官方文档中我找不到任何可以帮助我解决这个问题的内容。我想知道是否应该查找文档的其他部分,或者是否应该更改我的应用程序。
我们在 OneSignal 中使用新的 iOS 严重警报功能时遇到问题。我们拥有的应用程序是使用 Apache Flex 构建的,并且推送通知有效负载正在通过 Distriqt ANE 编译/生成并通
基于 this guide ,我尝试将我现有的 Android 应用程序与 OneSignal 集成。我将 OneSignal 代码放在 MainActivity.java 中: protected
我想知道我是否可以使用标签而不是 included_segments 为 OneSignal 中的特定用户发送通知 我想发送通知到特定的标签,而无需创建分割并根据他们过滤用户 $fields = ar
我是一名优秀的程序员,十分优秀!