Access / gcm-demo / sendAll. Reason: HTTP status code: 401

I get the following error when I try to send a message:

HTTP ERROR 500 Problem accessing /gcm-demo/sendAll. Reason: HTTP Status Code: 401 Caused by: com.google.android.gcm.server.InvalidRequestException: HTTP Status Code: 401 at com.google.android.gcm.server.Sender.sendNoRetry(Sender.java:177) at com.google.android.gcm.server.Sender.send(Sender.java:121) at com.google.android.gcm.demo.server.SendAllMessagesServlet.doPost(SendAllMessagesServlet.java:82) at javax.servlet.http.HttpServlet.service(HttpServlet.java:637) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511) at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:390) at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216) at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182) at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:766) at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418) at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:230) at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114) at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152) at org.mortbay.jetty.Server.handle(Server.java:326) at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542) at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:926) at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:549) at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212) at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404) at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:410) at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582) Powered by Jetty:// 

I am using Android Sample Project, as said here: http://developer.android.com/guide/google/gcm/demo.html

Can someone help me? Where does this error come from?

I am using Jetty on a Linux machine and compiling it on .war on a Windows Machine using Apache Ant ...

0
source share
3 answers

you can put the following code in the doPost () method before sending messages:

 import com.google.android.gcm.server.*; Sender sender = new Sender(myApiKey); Message message = new Message.Builder().build(); MulticastResult result = sender.send(message, devices, 5); 
+2
source

The sender is probably not authorized correctly.

Sender sender = new Sender(MY_KEY);

Is MY_KEY the same key that you registered with Google? Replace the API key as shown on the page

0
source

In the text editor, edit the samples / gcm -demo-server / WebContent / WEB-INF / classes / api.key and replace the existing text with the API key obtained above.

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

0
source

All Articles