Theo
Theo

Reputation: 3149

canonical_id zero in GCM - Android

I am struggling with a problem I am facing with GCM. The push notification is not send in my mobile phone:(. After sending a message from a simple form(I enter email of the user and the message),I get the following json response.

{
 "multicast_id":5448677994062381651,
 "success":1,
 "failure":0,
 "canonical_ids":0,
 "results":[{"message_id":"0:1463160271625523%cbfca9dcf9fd7ecd"}
]}

And this is my php file.

<?php
include("init.php");
$url = 'https://gcm-http.googleapis.com/gcm/send';
$apikey = 'xxxxxxxxxxxxxxxxxx';
$message="";
$registration_ids = array();
if(isset($_POST['submit'])){
    $name = $_POST['email'];
    $message = $_POST['message'];

    $sql = "SELECT * FROM user_info where email = '".$name."'";

    $result = mysqli_query($con,$sql);

    while($row = mysqli_fetch_array($result)){
        array_push($registration_ids,$row['token_id']);

    }
}

$message_send = array("Notice"=>$message);
$fields = array(
    'registration_ids' => $registration_ids,
    'data' => $message_send
);

$headers = array('Authorization: key='.$apikey,
                'Content-Type: application/json'
                );


$ch = curl_init();

curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,true);
curl_setopt($ch,CURLOPT_HTTPHEADER,$headers);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);

curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);

curl_setopt($ch,CURLOPT_POSTFIELDS,json_encode($fields));


$result = curl_exec($ch);
if($result === FALSE){
    die('Curl failed: ' . curl_error($ch));
}

curl_close($ch);
echo "done".$result;

?>
 <!DOCTYPE HTML>
 <html>
 <head>
   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Admin Area</title>
   <link rel="stylesheet" href="style.css" />
 </head>
<body>
<form method="post" action="index.php">
    <label>Enter email:</label>
    <input type="text" name="email"/>
    <label>Enter message:</label>
      <input type="message" name="message" rows="2" cols="30"/>

      <input type="submit" name="submit" value="Send"/>
</form>

What could be wrong? Could it be anything with the port numbers?

Thanks, Theo.

Upvotes: 0

Views: 140

Answers (1)

abielita
abielita

Reputation: 13469

Based from this documentation, "success":1 is the number of messages that were processed without an error. It does not mean that the message has been sent successfully. It can also mean that the message is queued for sending.

Also, "canonical_ids":0 does not mean that there was an error, it means that there were no devices that needed their ID's updated.

Check these related questions:

Upvotes: 1

Related Questions