OneSignal php 目标标签

OneSignal php target tags

我正在尝试使用此处找到的 OneSignal 服务的 api 向具有特定标签的用户发送推送通知:https://www.onesignal.com/

我似乎无法正确格式化数组。这是我拥有或想要的,但它不起作用:

"tags" => array[{"key": "NotifyLive", "relation": "=", "value": "true"}],

所以我想定位标签 "NotifyLive" 设置为 "true" 的用户。

我相信这是可以做到的,因为它显示在 documentation here 中。向下滚动到 tags:array of objects 示例。我只是想不出如何对这一行进行编码。

以下是我随通知发送的字段:

$fields = array(
      "app_id" => "example",
      "android_sound" => "$num",
      "big_picture" => "http://website.com/mypic.jpg",
      "tags" => array[{"key": "NotifyLive", "relation": "=", "value": "true"}],// Doesn't work! 
      "data" => array("autoplay" => "true"),
      "contents" => $content,
      "headings" => $heading
    );

错误: JSON 收到:{"allresponses":"{\"errors\":[\"Tags must be an array. For example, [{\"key\\": \\"gender\", \\"relation\" : \\"=\\", \\"value\":\\"male\"}]\"]}"}

该团队提供了惊人的支持,但我现在正在编写代码,因此需要在工作时间以外得到答复。感谢您的任何见解。

找到答案了。该数组必须以这种格式编写:

 // This Array format worked
 $daTags = array(
      array("key" => "NotifySound", "relation" => "=", "value" => "true"),
      );

    $fields = array(
      "app_id" => "exampleID",
      "android_sound" => "$num",
      "big_picture" => "http://wesite.com/mypic.jpg",
      "tags" => $daTags,
      "data" => array("autoplay" => "true"),
      "contents" => $content,
      "headings" => $heading
    );

由于 tags 字段已弃用,您应该使用 filters 字段通过标签定位用户

$filters = array(
    array("field" => "tag", "key" => "NotifySound", "relation" => "=", "value" => "true"),
);

$fields = array(
  "app_id" => "exampleID",
  "android_sound" => "sound",
  "big_picture" => "http://wesite.com/mypic.jpg",
  "filters" => $filters,
  "data" => array("autoplay" => "true"),
  "contents" => $content,
  "headings" => $heading
);