将推送通知发送到多个GCM ID返回错误:MISSING_REGISTRATIONS

时间:2015-07-01 09:04:52

标签: android push-notification google-cloud-messaging

我正在使用Google云消息传递向多个设备发送推送通知。以下是我发送的JSON数据:

{"to":["APA91bHMvoTuEYQAGwgB7Q-Em8j4DyZOrGXZJ9uTyFhddojDFHr0VeZUHAEgw_kk6QFmKQoWe6oN2fIgDAw9AoPigCqZ4BaMlNzxqWoBRx6Q3ZBBKTinzqUj8F7BEA5ZHmCIArsEB3zT","APA91bE4mP2TscsMf4IJT9-o70YSFPMo34NGGG4IXS4Oe9uuHawxTGplqd017NiGXC5ftlIUaXIIkI60nR7w5GI1UPy5IdqYDPt0_C1TW5S5o1zaGKfv9CKtb6CV3cDc1cvEKyCeMwUe3NZpX4UmhIGJfEmetQUNgg","APA91bHwfnK5l6CbHe_2SddBSHPJmuOxI0AapbyXAbuMVktFIICJx6WTu44ElkuxoBd70rsmdrdGSV7r9hDFvW-cBynunqOJAhI8PhKjDd2hINU91vP4_6yWRtRN2PYCXwkhkKxORrPcMi7pezt8FGhmynznIJpW9A"],"delay_while_idle":true,"collapse_key":"sample","delivery_receipt_requested":true,"data":{"message":"Stuffed Aloo Curry with Gatta Pulao by Chef Shelly","title":"Today's Special","request_type":"promotion"},"message_id":"m-313e76a8-b42c-4a8c-a1d4-ad58a059494a","time_to_live":10000}

我无法发送推送消息,我收到的信息低于消息

<success xmlns="urn:ietf:params:xml:ns:xmpp-sasl"></success>
<iq id='e0nLC-0' type='result'><bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'><jid>170453453515@gcm.googleapis.com/SmackAA9F4121</jid></bind></iq>
<iq id='e0nLC-1' type='result'></iq>
<message><gcm xmlns="google:mobile:data">{&quot;message_id&quot;:&quot;m-313e76a8-b42c-4a8c-a1d4-ad58a059494a&quot;,&quot;from&quot;:&quot;&quot;,&quot;error_description&quot;:&quot;InvalidJson: MISSING_REGISTRATIONS : Missing \&quot;to\&quot; field\nJSON_TYPE_ERROR : Field \&quot;to\&quot; must be a JSON java.lang.String: [\&quot;APA91bHMvoTuEYQAGwgB7Q-Em8j4DyZOrGXZJ9uTyFhddojDFHr0VeZUHAEgw_kk6QFmKQoWe6oN2fIgDAw9AoPigCqZ4BaMlNzxqWoBRx6Q3ZBBKTinzqUj8F7BEA5ZHmCIArsEB3zT\&quot;,\&quot;APA91bE4mP2TscsMf4IJT9-o70YSFPMo34NGGG4IXS4Oe9uuHawxTGplqd017NiGXC5ftlIUaXIIkI60nR7w5GI1UPy5IdqYDPt0_C1TW5S5o1zaGKfv9CKtb6CV3cDc1cvEKyCeMwUe3NZpX4UmhIGJfEmetQUNgg\&quot;,\&quot;APA91bHwfnK5l6CbHe_2SddBSHPJmuOxI0AapbyXAbuMVktFIICJx6WTu44ElkuxoBd70rsmdrdGSV7r9hDFvW-cBynunqOJAhI8PhKjDd2hINU91vP4_6yWRtRN2PYCXwkhkKxORrPcMi7pezt8FGhmynznIJpW9A\&quot;]&quot;,&quot;error&quot;:&quot;INVALID_JSON&quot;,&quot;message_type&quot;:&quot;nack&quot;}</gcm></message>

如果我使用单个gcmId作为String发送推送,它可以正常工作。但是,如果我将它发送到gcmId列表,我会得到错误响应:

  

“MISSING_REGISTRATIONS:Missing”到\“field \ nJSON_TYPE_ERROR:Field \”到\“必须是JSON java.lang.String”

1 个答案:

答案 0 :(得分:0)

发送多个注册ID时,您应该使用旧的“registration_ids”参数而不是“to”。

  

to - 此参数指定邮件的收件人。价值   必须是注册令牌或通知密钥。

     

registration_ids - 此参数指定设备列表   (注册令牌或ID)接收多播消息。它必须   包含至少1个且最多1000个注册ID。组播   允许使用消息(发送到多个注册ID)   仅限HTTP JSON格式。

(Source)

还提到here

  

虽然一般情况下不推荐使用它,但您可以将registration_ids用作多个设备(最多1000个)的多播消息的目标。