2

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:

Mr.Online
  • 306
  • 4
  • 15
Jeevan Thapa
  • 19
  • 1
  • 1
  • 3
  • Hi. Are you absolutely positive that the registration token you used is correct? – AL. Feb 20 '17 at 03:19
  • yes!!! bro, i have print token in console and paste token to firebase console,i'am sure token is correct. – Jeevan Thapa Feb 20 '17 at 05:44
  • If you don't mind, can you post a screenshot of the request? Also, with the same registration token, can you try sending a request via [cURL](http://stackoverflow.com/documentation/firebase-cloud-messaging/8242/firebase-cloud-messaging/26480/sending-downstream-messages-via-curl#t=201702200547358347206) or [Postman](http://stackoverflow.com/documentation/firebase-cloud-messaging/8242/firebase-cloud-messaging/26577/sending-downstream-messages-using-postman#t=201702200547358347206)? – AL. Feb 20 '17 at 05:48
  • How was it? Were you able to make it work? – AL. Feb 23 '17 at 03:16
  • no,, i have did all things but problem is not solve. – Jeevan Thapa Feb 26 '17 at 14:57

2 Answers2

2

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

AL.
  • 36,815
  • 10
  • 142
  • 281
eurosecom
  • 2,932
  • 4
  • 24
  • 38
  • 1
    cbuJIjkg9zQ%3AAPA91bHavuWCuRuWIBrDOoHUK-RsjU1yewigurrYzHe0cPiTQINykKjrLf8E0qEwJj3XmJ1IoTmn0r2EoLR_mAHGOjlA61CnQ8aSn2WxWKKByOwbsnqoVeaeWQIeGU_yh4wnZ67soLtI but here is difference, your token length is 152 but mine is 154. – Jeevan Thapa Feb 20 '17 at 08:45
  • @jeevanthapa The [format and length of a registration token varies](http://stackoverflow.com/a/39964597/4625829) so this shouldn't be an issue. – AL. Feb 20 '17 at 09:02
  • I have gained registration token in my app by extending FirebaseInstanceIdService. Where in FB console did you print your token ? – eurosecom Feb 20 '17 at 10:14
  • yes i have print and paste token i firebase console but it display invalid token. – Jeevan Thapa Feb 26 '17 at 14:55
  • Try to get registration token in your app by extending FirebaseInstanceIdService. I do not know if it's the same. – eurosecom Feb 26 '17 at 18:59
  • @jeevanthapa Hi. Do accept a correct answer (by clicking on the check mark in the left part of an answer) in order for your post to be properly tagged. Cheers! :) – AL. Mar 28 '17 at 22:40
0

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.

AL.
  • 36,815
  • 10
  • 142
  • 281
  • This is odd. Are you positive you're using the corresponding project (Sender ID) when sending to the generated registration token? Are you still seeing the same error? – AL. Feb 23 '17 at 05:56
  • 1
    yes,, done,thank u @Al ,, it causes error because of using encoded token. – Jeevan Thapa Mar 09 '17 at 11:44