当针对多个registration_ids时,FCM返回单个注册ID的响应

时间:2016-07-13 06:03:53

标签: android google-cloud-messaging firebase-cloud-messaging

我正在编写FCM实施的应用服务器端,它将向多个设备发送特定消息。

我使用registration_ids作为密钥,JsonArray使用多个收件人,但是返回的响应只显示给一个收件人,如下所示

{"multicast_id":7185150746202793615,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"InvalidRegistration"}]}

我不确定是否在firebase控制台中设置任何属性以启用多个注册ID接受。

以下是请求json

{  
   "registration_ids":[  
      [  
         "eU6HKx7QRMc:APA91bEIoJtHmTFz_MzUgbMkoZvwdlXzrMDbCB1via_fV16MRF_Xc0C0KkkVA1diR8QgzRdQtkCy-6JDd5it_NSaiIbIlBDDi0g2GFkmrE4ESMi43dBODBePQrzFLqiKeDmX26DkXB8i",
         "FERTeU6HKx7QRMc:APA91bEIoJtHmTFz_MzUgbMkoZvwdlXzrMDbCB1via_fV16MRF_Xc0C0KkkVA1diR8QgzRdQtkCy-6JDd5it_NSaiIbIlBDDi0g2GFkmrE4ESMi43dBODBePQrzFLqiKeDmX26DkXB8i"
      ]
   ],
   "notification":{  
      "title":"Hello FCM",
      "text":"Notification details"
   },
   "time_to_live":3600,
   "priority":"HIGH"
}

此请求的响应为

{  
   "multicast_id":7697036511101523125,
   "success":0,
   "failure":1,
   "canonical_ids":0,
   "results":[  
      {  
         "error":"InvalidRegistration"
      }
   ]
}

1 个答案:

答案 0 :(得分:4)

问题在于这个Json形成的请求。它必须是

{  
       "registration_ids"[ "eU6HKx7QRMc:APA91bEIoJtHmTFz_MzUgbMkoZvwdlXzrMDbCB1via_fV16MRF_Xc0C0KkkVA1diR8QgzRdQtkCy-6JDd5it_NSaiIbIlBDDi0g2GFkmrE4ESMi43dBODBePQrzFLqiKeDmX26DkXB8i",
             "FERTeU6HKx7QRMc:APA91bEIoJtHmTFz_MzUgbMkoZvwdlXzrMDbCB1via_fV16MRF_Xc0C0KkkVA1diR8QgzRdQtkCy-6JDd5it_NSaiIbIlBDDi0g2GFkmrE4ESMi43dBODBePQrzFLqiKeDmX26DkXB8i" ],
       "notification":{  
          "title":"Hello FCM",
          "text":"Notification details"
       },
       "time_to_live":3600,
       "priority":"HIGH"
    }

额外的方括号([])导致问题。