我参与了创建Google App Engine应用程序的教程,该应用程序可以通过GCM与我的Android应用程序进行通信。 https://developers.google.com/eclipse/docs/endpoints-androidconnected-gae
我还将我的服务器应用程序部署到了Google Cloud。除了最后一个步骤之外,本教程的所有步骤都有效。虽然我在我的服务器应用程序上成功注册了我的智能手机,但我无法向智能手机发送消息。有以下错误消息:
There was a problem when attempting to send the message using the server
at https://1-dot-fridge1710.appspot.com/_ah/api.
Is your API Key in MessageEndpoint.java (in your App Engine project) set correctly?
Here's the error information:
com.google.android.gcm.server.InvalidRequestException: HTTP Status Code: 401
com.google.api.server.spi.SystemService invokeServiceMethod: HTTP Status Code: 401
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 de.breckner.fridgemanager.MessageEndpoint.doSendViaGcm(MessageEndpoint.java:170)
at de.breckner.fridgemanager.MessageEndpoint.sendMessage(MessageEndpoint.java:145)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:45)
at com.google.api.server.spi.SystemService.invokeServiceMethod(SystemService.java:359)
at com.google.api.server.spi.SystemServiceServlet.execute(SystemServiceServlet.java:160)
at com.google.api.server.spi.SystemServiceServlet.doPost(SystemServiceServlet.java:118)
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$CachedChain.doFilter(ServletHandler.java:1166)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
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:765)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
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:923)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at com.google.tracing.TraceContext$TraceContextRunnable.runInContext(TraceContext.java:438)
at com.google.tracing.TraceContext$TraceContextRunnable$1.run(TraceContext.java:445)
at com.google.tracing.CurrentContext.runInContext(CurrentContext.java:220)
at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:309)
at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:301)
at com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:442)
at java.lang.Thread.run(Thread.java:724)
我认为问题是MessageEndpoint.java中的错误API密钥。我已经尝试了所有可能性,在Google Developers Console中创建了服务器API密钥,浏览器API密钥和Android API密钥,但它们都不起作用。 谁能告诉我如何解决这个问题?非常感谢你!
答案 0 :(得分:1)
官方文档说:
身份验证错误
您尝试用来发送邮件的发件人帐户无法通过身份验证。可能的原因是:
1. Authorization header missing or with invalid syntax.
2. Invalid project number sent as key.
3. Key valid but with GCM service disabled.
4. Request originated from a server not whitelisted in the Server Key IPs.
我在一个月前遇到同样的问题,我在标题中使用了错误的密钥。
你说你用API KEYS尝试了一切,检查你是不是从上面提到的东西。