HTTP Status Code: 401 in GCMDemo
Asked Answered
N

1

9

Reference:http://developer.android.com/google/gcm/demo.html

Server 401 when trying to send a message to my android device.

HTTP Status 500 - HTTP Status Code: 401

type Exception report

message HTTP Status Code: 401

description The server encountered an internal error (HTTP Status Code: 401) that        prevented it from fulfilling this request.

exception

com.google.android.gcm.server.InvalidRequestException: HTTP Status Code: 401
com.google.android.gcm.server.Sender.sendNoRetry(Sender.java:177)
com.google.android.gcm.server.Sender.send(Sender.java:121)
com.google.android.gcm.demo.server.SendAllMessagesServlet.doPost(SendAllMessagesServ    let.java:83)
javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.29 logs.

Could anybody tell me how to solve?Thank you!

Nicolette answered 21/12, 2012 at 5:47 Comment(1)
I fixed this by generating an extra, Server side, api key in google dev console.Calyces
S
14

You should take a look at the GCM docs where it explains the GCM response: http://developer.android.com/google/gcm/gcm.html#response and troubleshooting the 401 error code: http://developer.android.com/google/gcm/gcm.html#auth_error

Description from the docs:

Authentication Error The sender account that you're trying to use to send a message couldn't be authenticated. Possible causes are:

Authorization header missing or with invalid syntax.

Invalid project number sent as key.

Key valid but with GCM service disabled.

Request originated from a server not whitelisted in the Server Key IPs.

So I would check to make sure that you are setting you authorization header properly and that you Google Project number is properly setup with GCM and accepting your servers IP.

Straightjacket answered 22/12, 2012 at 16:18 Comment(3)
Thank you so much!I just verify the Google Project number and the api-key which is accepting my server IP.But still got that error...Nicolette
Then I would check to make sure that GCM is enabled in the Google Project, and allow all IP addresses just for a test.Straightjacket
Thank you for your answer!The reason is the api-key as you menthioned,when I changed the api-key and allowed all IP addresses,then messages were sent without any errors!Thank you for your help!Nicolette

© 2022 - 2024 — McMap. All rights reserved.