我读了实施谷歌gcm的基本示例。我开发了小型客户端Android应用程序,它成功地为我提供了gcm服务器的注册ID ..现在在服务器端我在rails上使用Ruby,因此我们使用这个gem来实现gcm github/dondeng/gcm_on_rails 。我将我的注册ID传递给我的服务器。 我成功运行了这些命令 lockquote blockquote device = Gcm :: Device.create(:registration_id = >XXXXXXXXXXXXXXXXXXXXXX)
notification = Gcm :: Notification.new
notification.device = device
notification.collapse_key = updates_available
notification.delay_while_idle =真
notification.data = {:registration_ids => [RegistrationID],:data => {:message_text =>Get on cloud nine}}
notification.save
用于传递通知:
$ rake gcm:notifications:deliver我的rake命令没有任何错误地运行。但完成所有这些任务后,我的设备没有收到任何消息..我不知道后台发生了什么。如何确认发送的消息正确接收设备..需要帮助...谢谢....
解决方案调试< GCM 信息可能非常麻烦并且很难。
一个可能的原因是GCM错误的 API密钥
a>,它必须在配置文件中定义。如果您使用了错误的API密钥,那么您可能会从服务器 {:code => 200,:message => nil} 获得成功响应,尽管没有消息已发送。在这种情况下,请转至 Google API控制台并查找正确的密钥。另一个可能的原因是设备的 REGISTRATION_ID 错误。如果REGISTRATION_ID不正确,您可能会收到 NotRegistered 或 InvalidRegistration 错误,该错误并不总是由gcm_on_rails插件识别(目前)。使用以下curl命令通过控制台调试API(插入API_KEY和设备的 REGISTRATION_ID )。
curl --headerAuthorization:key = API_KEY\ --header Content-Type:application / json\ https:// android.googleapis/gcm/send \ -d{\registration_ids\:[\REGISTRATION_ID\], \data\:{ \message_text \:\Test,Test \}}A成功/不成功尝试调用Gcm API应如下所示:
{multicast_id:7961 ..,success :1,failure:0,canonical_ids:1,results:[{registration_id:..,message_id:0:..}]} {multicast_id:7961 ..,success:0,failure:1,canonical_ids:0,results:[{error:NotRegistered} ]}最后另一个原因是当天无效的键:不要使用res像 message_type 这样的字作为数据散列中的关键字。它将返回一个状态码200,但它不会传送任何通知。 message_type 是高级选项之一(花了一个多小时才找到答案)。
I read basic example for implementing google gcm. I developed small client side android application which successfully gives me registration id from gcm server.. now on server side I am using Ruby on rails hence we use this gem for implementing server side of gcm github/dondeng/gcm_on_rails. I pass my registration id to to my server. I successfully ran these commands
device = Gcm::Device.create(:registration_id => "XXXXXXXXXXXXXXXXXXXXXX")
notification = Gcm::Notification.new
notification.device = device
notification.collapse_key = "updates_available"
notification.delay_while_idle = true
notification.data = {:registration_ids => ["RegistrationID"], :data => {:message_text => "Get on cloud nine"}}
notification.save
used to deliver notifications:
$ rake gcm:notifications:delivermy rake command running without any error. But after completion of all these tasks my device not receiving any message.. I don't know whats going on in background. How to confirm that sent message properly receive by device.. Need Help... Thank you....
解决方案Debugging GCM messages can be cumbersome and difficult.
One possible reason is a wrong API key for GCM, which must be defined in the configuration files. If you use the wrong API key, then you might get a success response from the server {:code=>200, :message=>nil}, although no message has been sent. In this case go to the Google API Console and look up the right key.
Another possible reason is a wrong REGISTRATION_ID for the device. if the REGISTRATION_ID is not correct you may get an NotRegistered or InvalidRegistration error, which is not always recognized by the gcm_on_rails plugin (at the moment). Use the following curl command to debug the API through the console (insert your API_KEY and the REGISTRATION_ID of the device).
curl --header "Authorization: key=API_KEY" \ --header Content-Type:"application/json" \ android.googleapis/gcm/send \ -d "{\"registration_ids\":[\"REGISTRATION_ID\"], \"data\":{\"message_text\":\"Test, Test\"}}"A successful / unsuccessful attempt to call the Gcm API should look like this:
{"multicast_id":7961..,"success":1,"failure":0,"canonical_ids":1, "results":[{"registration_id":"..","message_id":"0:.."}]} {"multicast_id":7961..,"success":0,"failure":1,"canonical_ids":0, "results":[{"error":"NotRegistered"}]}Finally another reason is an invalid key in the day: do not use a reserved word like message_type as a key in the data hash. It will return a status code 200, but it will not deliver any notification. message_type is one of the advanced options (took me more than an hour to find that out).
更多推荐
Android Gcm不适用于ROR
发布评论