Android GCM 错误=MissingRegistration 通过 JSON 发送消息
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22486192/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
GCM Error=MissingRegistration sending messages via JSON
提问by takayoshi
I'm testing push GCM via Fiddler
我正在测试通过 Fiddler 推送 GCM
Headers:
标题:
User-Agent: Fiddler
Authorization: key=AIzaSyAkXfcuLLCZ-5n18wwO6XeJ13g-z9ja
Host: android.googleapis.com
Content-Length: 286
Body:
身体:
{"registration_ids":["APA91bHyn8YHcH_vSuOo7_A0PMgF5SU1K0FebOFGKXYTqpN5x4eD0tVBvzQLn749TVcczN5gSjB1wqf5AzYfxFI_qskA1Nzipf-9MfdEom1PI1vkFqKIg9B8vZvPLOLozE7jaRzELuyDzpFRbO3Xh5lT-KDA"],"collapse_key":"8b990f5a-78fc-4bad-b242-ffc740a750fb","data":{"message":"message to device"}}
I've got a error
我有一个错误
Error=MissingRegistration
Where is my problem? All ids are correct.
我的问题在哪里?所有的id都是正确的。
回答by Eran
You probably forgot to specify the content type in the header to be JSON.
您可能忘记将标头中的内容类型指定为 JSON。
Content-Type: application/json
If Content-Type is omitted, the format is assumed to be plain text.
如果省略 Content-Type,则假定格式为纯文本。
And for plain text the registration ID is passed in a parameter called registration_id
instead of registration_ids
, which explains your MissingRegistration
error.
对于纯文本,注册 ID 在一个名为registration_id
而不是的参数中传递registration_ids
,这解释了您的MissingRegistration
错误。
回答by Zephyr
For the new cloud Message, when you want to send a dwonstream message from the server, you need to use "to" to declaim the target registration id.
对于新的云消息,当你想从服务器发送dwonstream消息时,你需要使用“to”来声明目标注册id。
like below :
像下面这样:
https://gcm-http.googleapis.com/gcm/send
Content-Type:application/json
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA
{ "data": {
"score": "5x1",
"time": "15:10"
},
"to" : "APA91bHun4MxP5egoKMwt2KZFBaFUH-1RYqx..."
}
回答by Hamedz
For Firebase, You can get info from https://firebase.google.com/docs/cloud-messaging/http-server-ref#error-codes
对于 Firebase,您可以从https://firebase.google.com/docs/cloud-messaging/http-server-ref#error-codes获取信息
Check that the request contains a registration token (in the registration_id in a plain text message, or in the to or registration_ids field in JSON).
检查请求是否包含注册令牌(在纯文本消息中的 registration_id 中,或者在 JSON 中的 to 或 registration_ids 字段中)。
回答by Shakeel Ahmed
Swift 5
斯威夫特 5
In my case receiver token was missing and after put the fcm receiver token its work fine for me