8

I have seen many similiar questions but no good answer despite some of them being accepted. I have registered for C2DM. I received confirmation email. Then I wrote some simple app to register for C2DM. I get the id (tried on emulator and on real device). Then I got the auth token (with curl) for my email that I used for C2DM registration (the same email that I use in app for acquiring the id).
When I try to do the push (also with curl), I get 401 error (like the auth token is wrong).

I read many tutorials and I am running out of ideas.

Sergey Glotov
  • 20,200
  • 11
  • 84
  • 98
DixieFlatline
  • 7,895
  • 24
  • 95
  • 147
  • Strange thing is, when i tried getting auth token for my email that was NEVER registred for c2dm, i also get auth token. So i think my auth token used for sending messages must be wrong. – DixieFlatline Oct 05 '11 at 17:51
  • I am also having the same issue. Android app registers with C2DM then sends user token to web server, my web server gets auth token from C2DM then sends push notification to registered app and all I get is 401 error. Maybe there is a problem with the C2DM service. Possibly not very reliable? – jamesc Oct 08 '11 at 23:53

2 Answers2

1

Let me try it (with curl only):

At first we are applying for the auth token:

curl.exe -v -k https://www.google.com/accounts/ClientLogin -d Email=xyz@gmail.com -d Passwd=secret -d accountType=GOOGLE -d source=your.registered.domain -d service=ac2dm

In the result your are receiving the auth token:

< HTTP/1.1 200 OK
SID=XXX
LSID=XXX
Auth=XXX
* Connection #0 to host www.google.com left intact
* Closing connection #0
* SSLv3, TLS alert, Client hello (1):

Please note that the Auth response is in the result with an uppercase first letter: "Auth=XXX"!

Now we are using the result for the next request but with lowercase first letter:
curl.exe -v -k --header "Authorization: GoogleLogin auth=XXX" https://android.apis.google.com/c2dm/send -d "registration_id=XXX" -d "data=helloooo" -d collapse_key=Z

And this works! But you are getting a 401 error, if you are using the auth like in the first response (upper case A in "Auth"):

curl.exe" -v -k --header "Authorization: GoogleLogin Auth=XXX" https://android.apis.google.com/c2dm/send -d "registration_id=XXX" -d "data=helloooo" -d collapse_key=Z

So the "auth" of request 2 is case sensitive. I think this is a pitfall 50% of the users are stepping into. Hope that helps.

ChrLipp
  • 15,526
  • 10
  • 75
  • 107
0

Maybe this is the problem?

http://groups.google.com/group/vogella/browse_thread/thread/95865344e6d2c734

Basucally, the "sender" parameter that you specifiy on teh Android device must be the same email address that is registred as the sender (server-side).

Ted
  • 19,727
  • 35
  • 96
  • 154
  • No, here the problem is between the sender (server-side) and the Google C2DM server. It's not related to the device. – Kamchatka Jun 12 '12 at 18:43