OneSignal php目标标签

时间:2016-05-03 06:32:41

标签: php onesignal

我正在尝试使用针对OneSignal服务的api向具有特定标记的用户发送推送通知:https://www.onesignal.com/

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

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

所以我想定位标记为“NotifyLive”的用户设置为“true”。

我相信这可以做到,因为它在documentation here中显示了它。向下滚动到标记:对象数组示例。我只是无法弄清楚如何编码这一行。

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

$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 \“:[\”标签必须是一个数组。例如,[{\\“key \\”:\\“gender \\”,\\“relation \\”:\\“= \\”,\\“value \\”:\\“male \ \ “}] \”]}“}

该团队拥有惊人的支持,但我现在需要在工作时间之外得到答案。感谢您的任何见解。

2 个答案:

答案 0 :(得分:10)

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

 // 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
    );

答案 1 :(得分:1)

由于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
);