Handle Unauthorized HTTP/1.1 401 – Android Push Notification (C2DM)

In our last article,  We discussed about powering your android application with Android Push Notification (c2dm) which should help any ecommerce or social networking business to send promotional offers to their end users. During implementation some developers might have faced issues like SERVICE_NOT_AVAILABLE while getting the registrationId from the android app or Issue like HTTP/1.1 401 Unauthorized while sending android push notification to the C2DM google service and looking for handle unauthorized HTTP/1.1 401. So here is our checklist to handle these type of errors:

Handle Unauthorized HTTP/1.1 401 and SERVICE_NOT_AVAILABLE Error:

  • Your “Role account email *” should be your google email account
  • Make sure your “Role account email *” was properly filed in the signup form
  • Setup your “Role account email *” in the emulator account once. This is not documented in the c2dm documentation but it worked like magic to get rid the error  HTTP/1.1 401 Unauthorized
  • In case you have setup you domain with google app (we enjoy google email and other services for our domain) then use option “GOOGLE_OR_HOSTED” OR “HOSTED” while generating Auth code.

We hope using this checklist, you should be able to get rid of the error for android push notification (c2dm). Please feel free to send us your thoughts or questions.

Handle Unauthorized HTTP/1.1 401 – Android Push Notification (C2DM) was last modified: May 15th, 2016 by Kapil Jain
  • Sujatha Balaraman

    I am stuggling to send a c2dm message to my sample application and am currently getting an unauthorized 401 error — so am wondering what I am missing:

    I created a whitelisted email id.. ensured that it was a gmail id….(gave the correct package name in the code.google. website.. with the request for whitelisting) — should the package name be the app name instead ?

    I was able to generate a registration id for the whitelisted gmail id with no issues.

    I was also able to generate the auth key.. however my question is that in the auth key curl script method I use.. I wanted to know what the -d source value should be ? Is this the app name or package name ? I tried with the auth key generated this way and it always yeilds a unauthorized.. any other ideas ?

    • Hi Sujatha,

      your source name can be your appname but I don’t think this is the reason for unauthorized 401 error. Please try following thing:
      1. Configure mail account in the Emulator/device with the whitelisted email Id
      2. if it doesn’t work then Signup again for c2dm with your email Id

      I hope this would help.


  • vamsi prakash

    pls elaborate

    Configure mail account in the Emulator/device with the whitelisted email Id

  • vamsi prakash

    i am getting HTTP/1.1 401 Unauthorized error in my logs of server