2

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

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

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

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

我相信这是可以做到的,因为它显示在此处的文档中。向下滚动到标签:对象数组示例。我只是不知道如何编码那一行。

以下是我与通知一起发送的字段:

$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\ \"}]\"]}"}

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

4

2 回答 2

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
    );
于 2016-05-03T07:07:11.180 回答
2

由于该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
);
于 2016-09-12T11:52:26.113 回答