2

I’m implementing Firebase Cloud Messaging (FCM) and am experiencing a problem that I’m unable to solve. I have implemented FirebaseMessagingService and FirebaseInstanceIdService according to the guide(s). When I go to Firebase Console for my app, and use the Notification function, I can successfully send a message to ALL my app instances (using the package name).

Now, in the code I have fetched the Firebase Instance Id (token) by use of the following code:

    String token = FirebaseInstanceId.getInstance().getToken();
    SendFirebaseTokenToServer(token);

(note that currently I’m using HTTP protocol, as my server does not yet have a cert). Anyway using the token I get from the call above, I go back to the Firebase Console and try to send a message to one (1) installed instance of my app. I grab the token from our server DB where it is stored as "varchar(max)". When I do that I get the following error message:

Invalid registration token. Check the token format.

I have googled that and found only one hit (having to do with Firebase and iOS):

http://stackoverflow.com/questions/41343520/ios-invalid-registration-token-check-the-token-format

That issue indicates that a cert was required (I think I’m reading it correctly). I’m not sure what I’m doing wrong. I need to get this to work using the Firebase Console first, then my server guy can start on his end knowing that it should work.

Saurabh
  • 71,488
  • 40
  • 181
  • 244
David M
  • 2,511
  • 1
  • 15
  • 18
  • Ok, i decided to try the Firebase Console directly (no server interaction) using the registration_id (token) i got from the Firebase call (spit out to Logcat). It worked! so the problem exists either on the server or in my sending it to the server. should i Encode() the token? – David M Apr 30 '17 at 19:02
  • 1
    If the problem exists in the code in your app server, edit your question to include the [minimal server code that reproduces the problem](http://stackoverflow.com/help/mcve). Without seeing that code, it'll be hard to say what's wrong with it. – Frank van Puffelen Apr 30 '17 at 20:24
  • @FrankvanPuffelen I am facing the same issue for the past few days. Could you please read my question? https://stackoverflow.com/questions/50359010 – bibscy May 15 '18 at 21:02

1 Answers1

1

Turns out i was programatically encoding all POST or PUT parameters prior to sending to our server. the FCM token had a semicolon in it, which got encoded to a "%3A", seemingly causing the problem.

do NOT encode the FCM token.

David M
  • 2,511
  • 1
  • 15
  • 18
  • Faced the exact same issue what i suggest here is you should encode FCM token specially when passing in query string and then on server side apply url decoding on it. – Umar Qureshi Sep 04 '17 at 21:03