Firebase Notifications - Invalid reg token, please check token format in Android

青春壹個敷衍的年華 提交于 2019-12-20 03:19:11

问题


![enter image description here][1]

If I send push message by selecting a package from Firebase console, the push goes to all devices, but during sending to individual device, it displays the error:

Invalid reg token,please check token format

Error Snapshot:

[

][1]

回答1:


UserID in console is not the registration token for Firebase messaging. By Firebase docs:

on initial startup of your app, the FCM SDK generates a registration token for the client app instance. If you want to target single devices or create device groups, you'll need to access this token by extending FirebaseInstanceIdService.

My last registration token looks like cpeBAc1NkUE:APA91bEpAKHQTdgkWVdDzDZG8BPon0APaIhbbuSejDpZF-FO1gD2saDV7_EQDo2WEz0H6e5U-uf0i-v4b25NXgGzV2oUrNuboM5675WY7VCP3JcBl8BCNY7eV0VFGHT9oRox0EEoo_ch




回答2:


In the other answer, you mentioned in the comments that you're Registration Token is:

cbuJIjkg9zQ%3AAPA91bHavuWCuRuWIBrDOoHUK-RsjU1yewigurrYzHe0cP‌​iTQINykKjrLf8E0qEwJj‌​3XmJ1IoTmn0r2EoLR_mA‌​HGOjlA61CnQ8aSn2WxWK‌​KByOwbsnqoVeaeWQIeGU‌​_yh4wnZ67soLtI

I noticed the % (percentage character) included in it, which isn't a usual character included in registration tokens. Figured that it was possible that this was encoded somehow. When decoded, this is the value:

cbuJIjkg9zQ:APA91bHavuWCuRuWIBrDOoHUK-RsjU1yewigurrYzHe0cP‌​iTQINykKjrLf8E0qEwJj‌​3XmJ1IoTmn0r2EoLR_mA‌​HGOjlA61CnQ8aSn2WxWK‌​KByOwbsnqoVeaeWQIeGU‌​_yh4wnZ67soLtI

Notice that the %3A was turned into : (colon). This is one of the usual characters. So I would suggest that you try the value above.

And as a reminder, the InvalidRegistration error (emphasis mine):

Check the format of the registration token you pass to the server. Make sure it matches the registration token the client app receives from registering with Firebase Notifications. Do not truncate or add additional characters.

Don't even encode it. Use it as is. Also, do note that the Registration Token should be kept secret.



来源:https://stackoverflow.com/questions/42324784/firebase-notifications-invalid-reg-token-please-check-token-format-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!