Reputation: 796
I am sending a GCM push message (less then 1000) with:
$Regids = mysql_query("SELECT regid FROM $tabel WHERE active = '1'");
$result_array = array();
while ($row = mysql_fetch_array($Regids)){
$result_array[] = $row['regid'];
}
$headers = array(
'Content-Type:application/json',
'Authorization:key=' . $serverApiKey
);
$data = array(
'registration_ids' => $result_array,
'data' => array(
'type' => 'New',
'title' => 'LH',
'msg' => ''.$msj.''
)
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
if ($headers)
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
$result = curl_exec($ch);
curl_close($ch);
When I print the $result
to check (and use for updating the database) it shows:
{"multicast_id":000,"success":274,"failure":75,"canonical_ids":13,"results":[{"message_id":"123"},{"message_id":"123"},{"error":"NotRegistered"},{"error":"NotRegistered"},{"message_id":"123"},{"message_id":"123"},{"registration_id":"456","message_id":"123"}]}
There is no },{ between every (canonical) registration_id
and the next (success) message_id
or error
.
(I shortened the response to make it readable)
So my update part fails
$result = json_decode($result);
for ($i = 0; $i < count($result->{'results'}); $i++) {
if ($result->{'results'}[$i]->{'message_id'}) {
...
} elseif($result->{'results'}[$i]->{'error'}) {
...
} elseif ($result->{'results'}[$i]->{'registration_id'}) {
...
}
}
Does someone know what's wrong?
Upvotes: 0
Views: 70
Reputation: 393771
The format of the response you got is correct . A message for which you get a canonical registration id is still accepted by Google and is therefore successful , and that's why you get a message id in addition to the canonical registration id for that message . That's why there are no brackets after the canonical registration id.
Upvotes: 2