【问题标题】:how to push message/notification to every subscriber of One Signal如何向 One Signal 的每个订阅者推送消息/通知
【发布时间】:2019-09-10 20:35:05
【问题描述】:

我可以使用其 id(通知密钥)向特定用户推送通知

public class SendNotification {

    public SendNotification(String message, String heading, String notificationKey){

        try {
            JSONObject notificationContent = new JSONObject(
                    "{'contents':{'en':'" + message + "'},"+
                    "'include_player_ids':['" + notificationKey + "']," +
                    "'headings':{'en': '" + heading + "'}}");
            OneSignal.postNotification(notificationContent, null);
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
}

在一个信号文档中 https://documentation.onesignal.com/docs/sending-notifications

在那里我们可以向所有人(所有订阅者)推送通知

我如何使用代码向每个人推送通知,因为我可以发送给单个订阅者

【问题讨论】:

    标签: android onesignal


    【解决方案1】:

    使用included_segments 键发送给所有Active Users

    更新:

    似乎使用include_player_ids 不需要API 密钥来发送消息。但是,使用 included_segments,确实 - “需要您的 OneSignal 应用程序的 REST API 密钥”

    已修改以下代码以包含 app_id 键。

    public class SendNotification {
    
        public SendNotification(String message, String heading, String notificationKey){
                try {
                JSONObject notificationContent = new JSONObject(
                        "{'app_id':\"YOUR_APP_ID\"," +
                        "'contents':{'en':'" + message + "'},"+
                        "'included_segments':[\"Active Users\"]," +
                        "'headings':{'en': '" + heading + "'}}");
                OneSignal.postNotification(notificationContent, null);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }
    

    https://documentation.onesignal.com/reference#section-example-code-create-notification

    【讨论】:

    • 我试过这个并且还使用“All”向所有订阅者发送通知,但是当我在我的问题中使用上述代码时它不起作用,它被发送并显示在一个信号仪表板中但使用这个代码发送给大家它不起作用
    • 我再次查看了我提供的链接,似乎使用 include_player_ids 不需要 API 密钥来发送消息。但是,使用 included_segments 确实 - “需要您的 OneSignal 应用程序的 REST API 密钥”,在 Segments 标题下
    • 兄弟看起来你的解决方案可以工作我得到这个错误你可以编辑放置 REST API KEY {"errors":["请包含区分大小写的授权标题:基本 \u003cYOUR-REST- API-KEY-HERE\u003e 具有有效的 REST API 密钥。"],"reference":["documentation.onesignal.com/docs/…}
    • 你可以在我添加的链接上看到。您可能想要使用 URI 生成器。享受吧!
    • 实际上有另一种格式的代码,但你转换为你的答案,所以如果你更好地知道请添加 REST API KEY 我从文档中复制了相同的代码,但它也不起作用。代码适用于 playerID,因此如果您可以帮助您提高技能,它将适用于细分
    猜你喜欢
    • 2020-01-25
    • 1970-01-01
    • 2016-08-14
    • 1970-01-01
    • 2015-06-30
    • 1970-01-01
    • 1970-01-01
    • 2021-08-21
    • 1970-01-01
    相关资源
    最近更新 更多