0

I'm currently working on GCM for android and implement the server code using PHP. Right now, my code looks like this:

$url = 'https://android.googleapis.com/gcm/send';
$registrationIDs = array('device1', 'device2');//device ids from database.

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

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

// Open connection
$ch = curl_init();

// Execute post
$result = curl_exec($ch);

// Close connection
curl_close($ch);

When I execute, the result are as follows:

{
  "multicast_id": 5407120473654582795,
  "success": 1,
  "failure": 1,
  "canonical_ids": 1,
  "results": [
    {
      "registration_id": "skjdfhksdfgksudghldshfgkdjfghdiugf",
      "message_id": "0:1354101888763222%14c0e050f9fd7ecd"
    },
    {
      "error": "MismatchSenderId"
    }
  ]
}

There are notes on GCM page:

  • If the message was created but the result returned a canonical registration ID, it's necessary to replace the current registration ID with the canonical one.
  • If the returned error is NotRegistered, it's necessary to remove that registration ID, because the application was uninstalled from the device.

My question are:

  1. Based on the server output, I have 1 canonical result. But, I'm not sure it belong to which device. How do I determine it?
  2. Based on question (1), I get the idea that I might be able to send device to GCM one at a time. But, this raise another question. What if I have millions of device, will that be OK?
Aziz Shaikh
  • 16,245
  • 11
  • 62
  • 79
ariefbayu
  • 21,849
  • 12
  • 71
  • 92

2 Answers2

1

Based on info on this page GCM Architectural Overview

It is the first element in your array that requires its regid replacing with the "skjdfhksdfgksudghldshfgkdjfghdiugf". The second element in the array was an out and out failure.

Millions of devices? - NO! Up to 1000 ? - Yes

On the same page was

registration_ids A string array with the list of devices (registration IDs) receiving the message. It must contain at least 1 and at most 1000 registration IDs.

NickT
  • 23,844
  • 11
  • 78
  • 121
0

You can read more about Canonical ID's on the GCM Advanced Topics page specifically:

If later on you try to send a message using a different registration ID, GCM will process the request as usual, but it will include the canonical registration ID in the registration_id field of the response. Make sure to replace the registration ID stored in your server with this canonical ID, as eventually the ID you're using will stop working.

You can also read more here in the Response Format section.

If you are sending to millions of devices you will have to send your message in blocks of 1000 registration Ids using JSON. The Google docs provides the following as an example of sending to six devices:

{ "data": {
    "score": "5x1",
    "time": "15:10"
  },
  "registration_ids": ["4", "8", "15", "16", "23", "42"]
}
selsine
  • 2,813
  • 2
  • 21
  • 22