如何修复OneSignal推送通知返回“未订阅所有包含的播放器”的问题?

时间:2019-04-08 08:03:53

标签: php onesignal

我正在尝试将通知发送到使用php安装了我的应用的设备,使用'included_segments' => array('All')时向所有用户成功发送通知 ,但是当我尝试使用过滤器时,我收到All included players are not subscribed响应错误,这是我正在使用的推送通知脚本:

push.php

<?PHP
function sendMessage(){
    $content = array(
        "en" => 'Testing Message'
        );

    $fields = array(
        'app_id' => <omitted>,
        'filters' => array(array("field" => "tag", "key" => "etab", "relation" => "=", "value" => "1")),
        'data' => array("foo" => "bar"),
        'large_icon' =>"ic_launcher_round.png",
        'contents' => $content
    );

    $fields = json_encode($fields);
print("\nJSON sent:\n");
print($fields);

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "https://onesignal.com/api/v1/notifications");
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json; charset=utf-8',
                                               'Authorization: Basic <omitted>'));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLOPT_HEADER, FALSE);
    curl_setopt($ch, CURLOPT_POST, TRUE);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);    

    $response = curl_exec($ch);
    curl_close($ch);

    return $response;
}

$response = sendMessage();
$return["allresponses"] = $response;
$return = json_encode( $return);
print("\n\nJSON received:\n");
print($return);
print("\n");
?>

输出

JSON sent: {"app_id":<omitted>,"filters":[{"field":"tag","key":"etab","relation":"=","value":"1"}],"data":{"foo":"bar"},"large_icon":"ic_launcher_round.png","contents":{"en":"Testing Message"}} JSON received: {"allresponses":"{\"id\":\"\",\"recipients\":0,\"errors\":[\"All included players are not subscribed\"]}"}

我检查了Android应用程序中的可用标签,并且该标签已成功实现并且可以正常使用。

1 个答案:

答案 0 :(得分:0)

"All included players are not subscribed"消息可能表示以下任何内容。

  1. 确保您设置了正确的app_id
  2. 您没有订阅的用户。
  3. 您尚未在OneSignal仪表板上的“应用程序设置”页面上为设备设置平台。
  4. 过滤器中没有用户。