dpkt31779 2016-05-03 06:32
浏览 12
已采纳

OneSignal php目标标签

I am trying to send a push notification to users with specific tags using the api for the OneSignal service found here: https://www.onesignal.com/

I can't seem to format the array correctly. Here is what I have or want but it's not working:

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

So I want to target users who have a Tag of "NotifyLive" set to "true".

I believe this can be done because it shows it in the documentation here. Scroll down to the tags:array of objects examples. I just can't figure out how to code that one line.

Here are the fields I am sending with my notification:

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

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

The team has AMAZING support but I need an answer outside of business hours as I am coding now. Thanks for any insights.

  • 写回答

2条回答 默认 最新

  • drol55885602 2016-05-03 07:07
    关注

    Figured out the answer. The array had to be written in this format:

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

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改