我想在oneSignal中创建Segments而不必访问仪表板,所以我想知道他们是否有适用于此的API或任何API 和我一起做的其他方式
答案 0 :(得分:3)
目前,OneSignal没有任何用于创建细分的api,但是如果您要将通知发送到特定组,则可以使用标签。
是的,您可以向特定标签发送通知,标签可以用作细分的替代。 如果要将通知发送到细分A,请将该用户的标签设置为{user:A} 并可以使用此php请求发送通知。
$fields = array(
'app_id' => YOUR_ONE_SIGNAL_APP_ID,
//'included_segments' => array('plant_a'),
'filters' => array(array("field" => "tag", "key" => "user", "relation" => "=", "value" => "A")),
'data' => array("foo" => "bar"),
'contents' => $content
);
您的完整代码将类似于
<?PHP
function sendMessage(){
$content = array(
"en" => 'English Message'
);
$fields = array(
'app_id' => YOUR_ONE_SIGNAL_APP_ID,
'filters' => array(array("field" => "tag", "key" => "user", "relation" => "=", "value" => "A")),
'data' => array("foo" => "bar"),
'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 REST_API_KEY'));
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");
?>
答案 1 :(得分:0)
根据他们的docs,不幸的是OneSignal目前没有此功能:
您可以添加到细分受众群的过滤器数量没有限制 或者您可以在OneSignal中创建的细分数量。 细分可能 只能从仪表板创建,但可以引用段 来自SDK和API。
答案 2 :(得分:0)
根据他们的文档[https://documentation.onesignal.com/reference#create-segments],您可以调用de api,但您需要一个ONESIGNAL PAID PLAN
答案 3 :(得分:0)
是的!可以通过REST API(reference)通过OneSignal Create Segments端点来完成。
这里是一个例子:
curl -XPOST -H'Authorization: Basic YOUR_REST_API_KEY' -H'Content-Type: application/json' https://onesignal.com/api/v1/apps/YOUR_APP_ID/segments
-d '{"name": "1", "filters": [{"field": "session_count", "relation": ">", "value": "1"},{"operator": "AND"}, {"field": "tag", "relation": "!=", "key": "tag_key", "value": "1"},{"operator": "OR"}, {"field": "last_session", "relation": "<", "value": "30"}]}'
响应类似于:
// Always true, "id" is uuid of created segment
{"success": true, "id": "7ed2887d-bd24-4a81-8220-4b256a08ab19"}