I am using this code
define('APPKEY','XXXXXXXXXXXXXX');
define('PUSHSECRET', 'XXXXXXXXXXXXX '); // Master Secret
define('PUSHURL', 'https://go.urbanairship.com/api/push/broadcast/');
$msg = "This is a message intended for my iPad 3";
$devicetokens = array();
$devicetokens[0] = $devicetoken;
$contents = array();
$contents['badge'] = "1";
$contents['alert'] = $msg;
$contents['sound'] = "default";
$push = array("aps" => $contents, "device_tokens" =>$devicetokens);
$json = json_encode($push);
$session = curl_init(PUSHURL);
curl_setopt($session, CURLOPT_USERPWD, APPKEY . ':' . PUSHSECRET);
curl_setopt($session, CURLOPT_POST, True);
curl_setopt($session, CURLOPT_POSTFIELDS, $json);
curl_setopt($session, CURLOPT_HEADER, False);
curl_setopt($session, CURLOPT_RETURNTRANSFER, True);
curl_setopt($session, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
$content = curl_exec($session);
var_dump($content); // just for testing what was sent
// Check if any error occured
$response = curl_getinfo($session);
But nothing happens - i get "device_token contains an invalid device token" ERROR
Does the device token need to be sent in a particular JSON format ? I can't find any documentation for this method . I got it from this question
Thanks in advance
Ok i got it working
The correct format is here
Needed to change the order and names of the JSON object and attributes
$msg = "This is a message intended for Nexus";
$devicetokens = array();
$devicetoken = "YOUR DEVICE TOKEN";
$devicetokens[0] = $devicetoken;
$contents = array();
$contents['alert'] = $msg;
$contents['sound'] = "default";
$push = array("apids" =>$devicetokens, "android" => $contents);
$json = json_encode($push);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.