我正在使用Google Cloud Messaging(GCM)处理推送通知.我可以在this tutorial之后设置服务器和客户端.
服务器在Apache Tomcat6.0(localhost)上运行,在Android API(API级别17)上运行Android模拟器.我有发件人ID和API密钥.从模拟器运行时,我获得了成功的设备连接消息.在此之后,从服务器发送消息后显示以下错误.
com.google.android.gcm.server.InvalidRequestException: HTTP Status Code: 401()
com.google.android.gcm.server.Sender.sendNoRetry(Sender.java:211)
com.google.android.gcm.server.Sender.send(Sender.java:125)
com.google.android.gcm.demo.server.SendAllMessagesServlet.doPost(SendAllMessagesServlet.java:83)
javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
从其他帖子,我理解错误的API密钥是罪魁祸首.但就我而言,我确保使用API控制台中正确的一个.
顺便说一句,当我运行模拟器时,我看到一条消息’将regId发送到服务器’.什么是注册ID?它与发件人ID不同;看起来像编码的.
有突破吗?
编辑
问题终于解决了! Ant没有正确构建WAR文件.因此API密钥几乎不会更新.发现这个虫子真是一场噩梦.谢谢大家的投入!
发件人ID是一个常量,将用于GCM和服务器之间的通信.当您的手机注册其服务时,regsitratiomID(regID)由GCM服务管理.
一个更好的定义:
http://developer.android.com/google/gcm/gcm.html
发件人ID:
A project number you acquire from the API console,as described in Getting Started. The sender ID is used in the registration process to identify an Android application that is permitted to send messages to the device.
注册ID:
An ID issued by the GCM servers to the Android application that allows it to receive messages. Once the Android application has the registration ID,it sends it to the 3rd-party application server,which uses it to identify each device that has registered to receive messages for a given Android application. In other words,a registration ID is tied to a particular Android application running on a particular device.