0

当我尝试发送消息时出现以下错误:

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://

我正在使用此处所述的 Android 示例项目:http: //developer.android.com/guide/google/gcm/demo.html

有人可以帮帮我吗?这个错误来自哪里?

我在 Linux 机器上使用 Jetty,并在使用 Apache Ant 的 Windows 机器上将其编译为 .war ...

4

3 回答 3

2

您可以在发送消息之前将以下代码放入 doPost() 方法中:

import com.google.android.gcm.server.*;

Sender sender = new Sender(myApiKey);
Message message = new Message.Builder().build();
MulticastResult result = sender.send(message, devices, 5);
于 2012-12-21T06:06:55.627 回答
0

The sender is probably not authorized with google 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 documentation page

于 2012-10-22T11:20:57.493 回答
0

在文本编辑器中,编辑 samples/gcm-demo-server/WebContent/WEB-INF/classes/api.key 并将现有文本替换为上面获得的 API 密钥。

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

于 2012-12-06T22:28:09.887 回答