No, not 401 again!

165 views
Skip to first unread message

Rene

unread,
Sep 29, 2010, 4:51:53 AM9/29/10
to android-c2dm
Sorry to bring this up again but I just spend hours reading all the
posts regarding 401 Unauthorized messages. I double checked my
applications but all with no luck. I keep getting 401 Unauthorized. So
hope someone sees what goes wrong here

1. I registered with the role account <myc2dmaccount>

2. From my Android I register the device with the google lib
com.google.android.c2dm the sender id is set to the <myc2dmaccount> .
I receive a registration id.

3. I request a authorization token from my server app. Below the
request logged with fiddler:

POST https://www.google.com/accounts/ClientLogin HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Host: www.google.com
Content-Length: 116
Expect: 100-continue

accountType=HOSTED_OR_GOOGLE&Email=<myc2dmaccount>&Passwd=<myPassword>=ac2dm&source=<Android
app packagename>

This returns a authorization ID

4. I now call the send api like:

POST https://android.apis.google.com/c2dm/send HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Authorization: GoogleLogin auth=<Authorization token>
Host: android.apis.google.com
Content-Length: 155
Expect: 100-continue

registration_id=<registration id>&collapse_key=group1

the response I get is:

HTTP/1.1 401 Unauthorized
Update-Client-Auth: <a token>
Set-Cookie: DO_NOT_CACHE_RESPONSE=true;Expires=Wed, 29-Sep-2010
08:48:12 GMT
Content-Type: text/html; charset=UTF-8
Date: Wed, 29 Sep 2010 08:48:11 GMT
Expires: Wed, 29 Sep 2010 08:48:11 GMT
Cache-Control: private, max-age=0
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
Server: GSE
Content-Length: 147

<HTML>
<HEAD>
<TITLE>Unauthorized</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>Unauthorized</H1>
<H2>Error 401</H2>
</BODY>
</HTML>

What is wrong here?

Rene

unread,
Sep 29, 2010, 5:11:00 AM9/29/10
to android-c2dm
I just saw the Update-Client-Auth: header and tried sending with this
updated token. No luck. I still get a 401 but now without the Update-
Client-Auth header:


HTTP/1.1 401 Unauthorized
Content-Type: text/html; charset=UTF-8
Date: Wed, 29 Sep 2010 09:07:23 GMT
Expires: Wed, 29 Sep 2010 09:07:23 GMT

Yanislav Mihaylov

unread,
Sep 29, 2010, 6:25:25 AM9/29/10
to androi...@googlegroups.com
HI,
Excuse me but I'm new to the C2DM and still can not make it working.
My problem is that I don't get the registration event.
I noticed that you mentioned that first you "1. I registered with the role account <myc2dmaccount>"
What does it mean?

Thanks and Best Regards,
Yanislav

Costin Manolache

unread,
Sep 29, 2010, 12:30:13 PM9/29/10
to androi...@googlegroups.com
Could you send me a private email with the account you're using ?

If you have both a hosted and a google ( consumer ) account with the same email - it may explain the problem.

Costin

Yanislav

unread,
Sep 30, 2010, 8:01:42 AM9/30/10
to android-c2dm
Hi,
Have you managed to make it working?
For me it is not clear what I have to put in the service parameter
during the login.
Do we have to put really our package name and is it necessary to be
the package which is provided to google during the registration?

Thanks and Best Regards,
Yanislav


> > accountType=HOSTED_OR_GOOGLE&Email=<myc2dmaccount>&Passwd=<myPassword>=ac2d m&source=<Android

Yanislav Mihaylov

unread,
Sep 30, 2010, 8:27:11 AM9/30/10
to android-c2dm
It seems that the magic is to set the service to be ac2dm bot the application package.

Now it works for me :-)

Rene

unread,
Sep 30, 2010, 2:19:03 PM9/30/10
to android-c2dm
Yanislav,

You need to register an google account for the service. This account
will be whitelisted on the google servers so you can call the C2DM
api. You can sign up here:

http://code.google.com/intl/nl-NL/android/c2dm/signup.html

The steps are explained here http://code.google.com/intl/nl-NL/android/c2dm/

Rene
> > accountType=HOSTED_OR_GOOGLE&Email=<myc2dmaccount>&Passwd=<myPassword>=ac2d m&source=<Android

Rene

unread,
Sep 30, 2010, 2:29:02 PM9/30/10
to android-c2dm
Hi,

Good that you have it working. I am jealous ;-)

It is still not working at this end. The configuration seems to be
good but I keep getting the 401 back.

I don't understand what you wanted to write about the application
package.

I used the packagename but I don't think it matters. It is a string
using for logging purposes on the google servers. According to the
documentation:

Short string identifying your application, for logging purposes. This
string should take the form:
"companyName-applicationName-versionID".

As far as I can see to get access to the api you only have to get a
authorization token for the ac2dm service with an google account that
is whitelisted. I assume if something is wrong on the phone side I
will be able to reach the api but will get an error back as decscribed
in the documentation.

Rene

Naperville Jim

unread,
Oct 5, 2010, 3:05:40 PM10/5/10
to android-c2dm
I am having exactly the same problem as Rene. I have never received a
update-client-auth header but the headers and html content I receive
is the same as what Rene got after updating the token.

I am doing the same thing in that I'm using an auth token that just
came back from a successful call to ClientLogin.

I did notice that the send url being used in the jumpnote example is

https://android.clients.google.com/c2dm/send

rather than the one in the c2dm doc that we are using, but changing
the url produced the same 401 response.

Costin Manolache

unread,
Oct 5, 2010, 6:37:16 PM10/5/10
to androi...@googlegroups.com
In order to debug I need:
- the auth token you got back from ClientLogin ( please sent it privately to me, not on the list - the token can only be used for sending messages, I need to decode it to make sure it is good )
- the user on the phone
- the sender Id 

In Rene's case: the auth token is for a different user, make sure the role account used by the application matches the sender account. 

Costin

Costin Manolache

unread,
Oct 5, 2010, 8:06:28 PM10/5/10
to androi...@googlegroups.com
For Jim: the account was not enabled for C2DM, please fill out the Sign Up form again.
It is important to have the account created before you fill the signup form. 

I should add that in Rene's case, the sender account declared on the android app was ok - however the account actually used was different, and not registered with C2DM. 

The 401 was sent in both cases because of 'sender account not registered (white listed) with C2DM'.

Sorry for the confusion, I failed to check the simplest cause first.


Costin

Rene

unread,
Oct 6, 2010, 3:08:08 AM10/6/10
to android-c2dm
Costin,

It would help a lot if the 401 message returned more information.

- Is the sender account used not authorized (not whitelisted)?
- Is the authorization token for the correct service?
- Does the sender account match the email account of the registration
id from the mobile?

This would make it much easier to find the cause of the 401 return.
And would save you tons of time ;-)

Thanks.

Rene

Thomas Dybdahl Ahle

unread,
Mar 22, 2011, 10:22:32 AM3/22/11
to androi...@googlegroups.com, Costin Manolache
I have the exact same problem.

I can log in to google.com using the account, but I only use it for c2dm. It is also not hosted.
Is this a problem?
Reply all
Reply to author
Forward
0 new messages