From f1598d1852e0c35db6bad40da162eca15680077e Mon Sep 17 00:00:00 2001
From: Eric Gilmore Once the XMPP connection is established, CCS and your server use normal XMPP
Server
<success xmlns="urn:ietf:params:xml:ns:xmpp-sasl"/>
-Message Format
+Downstream Messages
<message> stanzas to send JSON-encoded messages back and
forth. The body of the <message> must be:
For each device message your app server receives from CCS, it needs to send an ACK message. It never needs to send a NACK message. If you don't send an ACK for a message, -CCS will just resend it. +CCS resends it the next time a new XMPP connection is established, unless the +message expires first.
CCS also sends an ACK or NACK for each server-to-device message. If you do not receive either, it means that the TCP connection was closed in the middle of the @@ -316,7 +315,7 @@ connection, but allowing whatever is already in the pipeline to continue. When y a {@code CONNECTION_DRAINING} message, you should immediately begin sending messages to another CCS connection, opening a new connection if necessary. You should, however, keep the original connection open and continue receiving messages that may come over the connection (and -ACKing them)—CCS will handle initiating a connection close when it is ready.
+ACKing them)—CCS handles initiating a connection close when it is ready.The {@code CONNECTION_DRAINING} message looks like this:
<message> @@ -330,66 +329,11 @@ ACKing them)—CCS will handle initiating a connection close when it is read{@code CONNECTION_DRAINING} is currently the only {@code control_type} supported.
-Upstream Messages
- -Using CCS and the - -{@code GoogleCloudMessaging} -API, you can send messages from a user's device to the cloud.
- -Here is how you send an upstream message using the - -{@code GoogleCloudMessaging} -API. For a complete example, see Implementing GCM Client:
- -GoogleCloudMessaging gcm = GoogleCloudMessaging.get(context); -String GCM_SENDER_ID = "Your-Sender-ID"; -AtomicInteger msgId = new AtomicInteger(); -String id = Integer.toString(msgId.incrementAndGet()); -Bundle data = new Bundle(); -// Bundle data consists of a key-value pair -data.putString("hello", "world"); -// "time to live" parameter -// This is optional. It specifies a value in seconds up to 24 hours. -int ttl = [0 seconds, 24 hours] - -gcm.send(GCM_SENDER_ID + "@gcm.googleapis.com", id, ttl, data); -- -This call generates the necessary XMPP stanza for sending the upstream message. -The message goes from the app on the device to CCS to the 3rd-party app server. -The stanza has the following format:
- -<message id=""> - <gcm xmlns="google:mobile:data"> - { - "category":"com.example.yourapp", // to know which app sent it - "data": - { - "hello":"world", - }, - "message_id":"m-123", - "from":"REGID" - } - </gcm> -</message>- -Here is the format of the ACK expected by CCS from 3rd-party app servers in -response to the above message:
- -<message id=""> - <gcm xmlns="google:mobile:data"> - { - "to":"REGID", - "message_id":"m-123" - "message_type":"ack" - } - </gcm> -</message>+Receive delivery receipts
-You can use upstream messaging to get delivery receipts (sent from CCS to +
You can get delivery receipts (sent from CCS to your 3rd party app server) when a device confirms that it received a message sent by CCS.
@@ -452,8 +396,68 @@ app server that a device received a message that CCS sent it: which in this example is {@code dr2:m-1366082849205}.
Using CCS and the + +{@code GoogleCloudMessaging} +API, you can send messages from a user's device to the cloud.
+ +Here is how you send an upstream message using the + +{@code GoogleCloudMessaging} +API. For a complete example, see Implementing GCM Client:
+ +GoogleCloudMessaging gcm = GoogleCloudMessaging.get(context);
+String GCM_SENDER_ID = "Your-Sender-ID";
+AtomicInteger msgId = new AtomicInteger();
+String id = Integer.toString(msgId.incrementAndGet());
+Bundle data = new Bundle();
+// Bundle data consists of a key-value pair
+data.putString("hello", "world");
+// "time to live" parameter
+// This is optional. It specifies a value in seconds up to 24 hours.
+int ttl = [0 seconds, 24 hours]
+
+gcm.send(GCM_SENDER_ID + "@gcm.googleapis.com", id, ttl, data);
+
+
+This call generates the necessary XMPP stanza for sending the upstream message. +The message goes from the app on the device to CCS to the 3rd-party app server. +The stanza has the following format:
+ +<message id="">
+ <gcm xmlns="google:mobile:data">
+ {
+ "category":"com.example.yourapp", // to know which app sent it
+ "data":
+ {
+ "hello":"world",
+ },
+ "message_id":"m-123",
+ "from":"REGID"
+ }
+ </gcm>
+</message>
+
+Here is the format of the ACK expected by CCS from 3rd-party app servers in +response to the above message:
+ +<message id="">
+ <gcm xmlns="google:mobile:data">
+ {
+ "to":"REGID",
+ "message_id":"m-123"
+ "message_type":"ack"
+ }
+ </gcm>
+</message>
+
+
Every message sent to CCS receives either an ACK or a NACK response. Messages @@ -468,7 +472,7 @@ figure 1:
Figure 1. Message/ack flow. -Conversely, to avoid overloading the 3rd-party app server, CCS will stop sending +
Conversely, to avoid overloading the 3rd-party app server, CCS stops sending if there are too many unacknowledged messages. Therefore, the 3rd-party app server should "ACK" upstream messages, received from the client application via CCS, as soon as possible to maintain a constant flow of incoming messages. The aforementioned pending message limit doesn't @@ -663,7 +667,7 @@ public class SmackCcsClient { * Creates a JSON encoded GCM message. * * @param to RegistrationId of the target device (Required). - * @param messageId Unique messageId for which CCS will send an + * @param messageId Unique messageId for which CCS sends an * "ack/nack" (Required). * @param payload Message content intended for the application. (Optional). * @param collapseKey GCM collapse_key parameter (Optional). diff --git a/docs/html/google/gcm/gcm.jd b/docs/html/google/gcm/gcm.jd index 4e345b3..d4bb45e 100644 --- a/docs/html/google/gcm/gcm.jd +++ b/docs/html/google/gcm/gcm.jd @@ -279,7 +279,7 @@ receives match the logged in user.
An app can be automatically unregistered after it is uninstalled. +
A client app can be automatically unregistered after it is uninstalled. However, this process does not happen right away. What happens in this scenario is as follows:
If you receive authentication errors when sending messages, check the validity +of your API key. For example, on Android, run the following command:
+ +# api_key=YOUR_API_KEY
+
+# curl --header "Authorization: key=$api_key" \
+ --header Content-Type:"application/json" \
+ https://android.googleapis.com/gcm/send \
+ -d "{\"registration_ids\":[\"ABC\"]}"
+
++If you receive a 401 HTTP status code, your API key is not valid. Otherwise you +should see something like this:
+ +
+{"multicast_id":6782339717028231855,"success":0,"failure":1,
+"canonical_ids":0,"results":[{"error":"InvalidRegistration"}]}
+
+
++If you want to confirm the validity of a registration ID, you can do so by +replacing "ABC" with the registration ID. +
+When a JSON request is successful (HTTP status code 200), the response body -contains a JSON object with the following fields:
-| Field | -Description | -
|---|---|
multicast_id |
- Unique ID (number) identifying the multicast message. | -
success |
- Number of messages that were processed without an error. | -
failure |
- Number of messages that could not be processed. | -
canonical_ids |
- Number of results that contain a canonical registration ID. See -Advanced Topics for more discussion of this topic. | -
results |
- Array of objects representing the status of the messages processed. The
-objects are listed in the same order as the request (i.e., for each registration
-ID in the request, its result is listed in the same index in the response) and
-they can have these fields: -
|
-
When a JSON request is successful (HTTP status code 200), the JSON object returned +contains the +Downstream HTTP message response body.
+If the value of failure and canonical_ids is 0, it's
not necessary to parse the remainder of the response. Otherwise, we recommend
that you iterate through the results field and do the following for each object
@@ -227,8 +210,9 @@ device, or the client app isn't configured to receive
messages.
Here are the recommendations for handling the different types of error that -might occur when trying to send a message to a device:
- -registration_id parameter in a plain text message, or in the
-registration_ids field in JSON).
-MissingRegistration.InvalidRegistration.MismatchSenderId.NotRegistered.MessageTooBig.from or any value
-prefixed by google.) that is used internally by GCM and therefore cannot be used.
-Note that some words (such as collapse_key) are also used by GCM
-but are allowed in the payload, in which case the payload value will be
-overridden by the GCM value.
-InvalidDataKey.InvalidTtl.
-# api_key=YOUR_API_KEY
-
-# curl --header "Authorization: key=$api_key" --header Content-Type:"application/json" https://android.googleapis.com/gcm/send -d "{\"registration_ids\":[\"ABC\"]}"
-
-
-
-If you receive a 401 HTTP status code, your API key is not valid. Otherwise you
-should see something like this:
-{"multicast_id":6782339717028231855,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"InvalidRegistration"}]}
-
-If you want to confirm the validity of a registration ID, you can do so by
-replacing "ABC" with the registration ID.
-Retry-After header if it's included in the response
-from the GCM server.error field of a JSON object in the results array is Unavailable.
-error field of a JSON
-object in the results array is InternalServerError.
-InvalidPackageName.
-DeviceMessageRateExceeded.This section shows a few examples of responses indicating messages that were diff --git a/docs/html/google/gcm/server-ref.jd b/docs/html/google/gcm/server-ref.jd index a94e727..2a41e58 100644 --- a/docs/html/google/gcm/server-ref.jd +++ b/docs/html/google/gcm/server-ref.jd @@ -665,7 +665,8 @@ matches the value passed in the request. Check that the token you're sending inside the Authentication header is the correct API key associated with your project. See -GCM HTTP Connection Server for details. +Checking the validity of an API Key + for details.