-->

Firebase Notifications - Invalid reg token, please

2019-02-27 08:27发布

问题:

![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.