【问题标题】:OneSignal - Sending Notification Base on TagsOneSignal - 基于标签发送通知
【发布时间】:2017-08-17 12:27:54
【问题描述】:

我想知道是否可以在 OneSignal 中通过使用标签而不是包含的段来为特定用户发送通知 我想发送通知 到特定标签,而无需创建细分并根据它们过滤用户

$fields = array(
        'app_id' => "XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX",
        'included_segments' => array($segments),
        'data' => array("foo" => "bar"),
        'contents' => $content
    );

【问题讨论】:

    标签: android ios push-notification onesignal


    【解决方案1】:

    在下面的示例中,如果 level>10 或 amount_spent>0 是过滤条件,其中 level 和 amount_spent 是相应标签的键。

        try {
           String jsonResponse;
    
           URL url = new URL("https://onesignal.com/api/v1/notifications");
           HttpURLConnection con = (HttpURLConnection)url.openConnection();
           con.setUseCaches(false);
           con.setDoOutput(true);
           con.setDoInput(true);
    
           con.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
           con.setRequestProperty("Authorization", "Basic NGEwMGZmMjItY2NkNy0xMWUzLTk5ZDUtMDAwYzI5NDBlNjJj");
           con.setRequestMethod("POST");
    
           String strJsonBody = "{"
                          +   "\"app_id\": \"5eb5a37e-b458-11e3-ac11-000c2940e62c\","
                          +   "\"filters\": [{\"field\": \"tag\", \"key\": \"level\", \"relation\": \">\", \"value\": \"10\"},{\"operator\": \"OR\"},{\"field\": \"amount_spent\", \"relation\": \">\",\"value\": \"0\"}],"
                          +   "\"data\": {\"foo\": \"bar\"},"
                          +   "\"contents\": {\"en\": \"English Message\"}"
                          + "}";
    
    
           System.out.println("strJsonBody:\n" + strJsonBody);
    
           byte[] sendBytes = strJsonBody.getBytes("UTF-8");
           con.setFixedLengthStreamingMode(sendBytes.length);
    
           OutputStream outputStream = con.getOutputStream();
           outputStream.write(sendBytes);
    
           int httpResponse = con.getResponseCode();
           System.out.println("httpResponse: " + httpResponse);
    
           if (httpResponse >= HttpURLConnection.HTTP_OK && httpResponse < HttpURLConnection.HTTP_BAD_REQUEST) {
               Scanner scanner = new Scanner(con.getInputStream(), "UTF-8");
               jsonResponse = scanner.useDelimiter("\\A").hasNext() ? scanner.next() : "";
               scanner.close();
           }else {
              Scanner scanner = new Scanner(con.getErrorStream(), "UTF-8");
              jsonResponse = scanner.useDelimiter("\\A").hasNext() ? scanner.next() : "";
              scanner.close();
       }
       System.out.println("jsonResponse:\n" + jsonResponse);
    
    }   catch(Throwable t) {
        t.printStackTrace();
    }
    

    取自:Source。 搜索 Send based on filters/tags - Create notification 从提到的来源

    【讨论】:

    • @Hooda 你能帮忙告诉我如何在我的应用程序中验证级别的标签值吗?
    猜你喜欢
    • 2018-01-22
    • 1970-01-01
    • 1970-01-01
    • 2015-07-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-21
    相关资源
    最近更新 更多