0

I'm trying to run the GCM demo. I've built and installed the app on my phone and now am trying to fire the POST to activate the push.

I generated the google-services.json file and during that process got a server key (API_KEY) and a Sender ID (SID). (Is the sender ID the 'to' device/app token?)

I'm trying to send with this post:

curl -vvv -X POST --header "Content-Type: application/json" --header "project_id: default-demo-app-92a8c" --header "Authorization: key=<<API_KEY>>" --data @- "https://android.googleapis.com/gcm/send" << EOF
{
   "to": "<<SID>>",
   "data": {
    "message":"Hello"
    }
}
EOF

This is the response:

*   Trying 74.125.29.95...
* Connected to android.googleapis.com (74.125.29.95) port 443 (#0)
* TLS 1.2 connection using TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
* Server certificate: *.googleapis.com
* Server certificate: Google Internet Authority G2
* Server certificate: GeoTrust Global CA
> POST /gcm/send HTTP/1.1
> Host: android.googleapis.com
> User-Agent: curl/7.43.0
> Accept: */*
> Content-Type: application/json
> project_id: default-demo-app-92a8c
> Authorization: key=AIzaSyA2GFGsoIeppqKRTpSc6m4sffGD8dzqryY
> Content-Length: 58
>
* upload completely sent off: 58 out of 58 bytes
< HTTP/1.1 400 Bad Request
< Content-Type: text/plain; charset=UTF-8
< Date: Tue, 26 Jan 2016 21:46:48 GMT
< Expires: Tue, 26 Jan 2016 21:46:48 GMT
< Cache-Control: private, max-age=0
< X-Content-Type-Options: nosniff
< X-Frame-Options: SAMEORIGIN
< X-XSS-Protection: 1; mode=block
< Server: GSE
< Alternate-Protocol: 443:quic,p=1
< Alt-Svc: quic=":443"; ma=604800; v="30,29,28,27,26,25"
< Accept-Ranges: none
< Vary: Accept-Encoding
< Transfer-Encoding: chunked
<
INVALID_REGISTRATION
* Connection #0 to host android.googleapis.com left intact

Why am I getting this error?

Greg
  • 10,696
  • 22
  • 68
  • 98

1 Answers1

0

Is the sender ID the 'to' device/app token?

The Sender ID is a unique numerical value created when you configure your API project (given as "Project Number" in the Google Developers Console). The sender ID is used in the registration process to identify an app server that is permitted to send messages to the client app. (source)

The value for to should be the client app's registration token.

You can look at the Simple Downstream Messaging page of the GCM documentation for more useful information.

adjuremods
  • 2,938
  • 2
  • 12
  • 17
  • That makes sense. How can I see this token, as it sounds like its obtained by the app (the GCM sample app from Google in my case)? My need is to verify the server-side push--don't know anything about mobile apps. If I can see that token I can try pushing to it and confirm in the sample app that the message is displayed. When I start the sample app it says "Token retrieved and sent to server!", but it doesn't show me what the token is. – Greg Jan 27 '16 at 17:05
  • @Greg: IMO, you can refer to my answer at http://stackoverflow.com/questions/33489862/google-gcm-token-vs-registration-id/33490670#33490670 for more information. About `but it doesn't show me what the token is`, I think you can use `Log.i(...)`, for example, to see. – BNK Jan 28 '16 at 01:46