1

I have an application which till now was using pure GCM integration for Android and pure APNS integration for iOS. Client application registers for Push Notification service and send back registration token to my server, which I can use to send targeted messages. This is existing system. Now I have imported my GCM project into Firebase, and Android and iOS application configs are added to project. This way, I can integrate Firebase SDK in next version of my apps and use enhanced notification capabilities.

Next step was to change backend implementation and use Firebase console to send notifications. Instance ID batchImport API was really straight forward, I took APNS token from my database, and API returned the registration token. This I used in Firebase to single device and notification was triggered. I could even subscribe this token to the topic I wished.

But now I am trying to use Android GCM registration token in Firebase console, no error, but notification is not triggered. When I tried to subscribe for topic using batchAdd, I received following output with HTTP response 400.

{
  "error": "InvalidTokenVersion"
}

I have not found any documentation on this error, and how to correct same. The token I used is perfectly valid since I can trigger notifications using same via old GCM server code.

GCM token looks like this

APA91bE_uLJ4dyXXXXX_Tn2qbCWgzCW4GR6t78_z-Up_gSdX7tekiSKWmXXXXXwSainHPTz5hQ6XM8F-j3XLKZuIUgNM84v_XXXXXeJ1pX_YBTn5OUNnZte2uSSisLBqQwCPGYXXXXXX

New token generated after importing APNS tokens, there is difference in token length, nothing else I can find.

cUt0RhCYXXX:APA91bG5JraXXXXX1M2lFHjzw_XXXXXg2qGQZ_iUDjoaXXXXXw4vv0JND24-4hj5ppvsXXXXXV4WWgNsurteN_nXXXXXi3SfzjBXZt5X00PXzhb3XXXXXlf_WDVxoIvkXXXXXRd2Rw1
Diego Giorgini
  • 12,489
  • 1
  • 47
  • 50
Ashish Patil
  • 818
  • 7
  • 15
  • Hi Ashish. Just to clarify, are you using the *new* token when getting `InvalidTokenVersion` error? – AL. Apr 10 '17 at 03:52
  • 2
    I am using my existing GCM registration token. If FCM is expecting tokens in different version, there must be a way to convert existing reg tokens to new version of FCM compatible tokens, just like we imported APNS tokens. – Ashish Patil Apr 10 '17 at 05:57
  • Could you post a sample format of the token? AFAIK, old tokens (most recent GCM version) should be compatible with FCM. However, if your token was generated using an older GCM method (like `.register()`), I think you'll have to update your implementation (maybe use FCM) to generate a more recent version of the token (see [here](http://stackoverflow.com/a/37332566/4625829) -- I've asked a question in this answer, but it looks like it's not compatible for deprecated versions of GCM). – AL. Apr 10 '17 at 06:09
  • @AL. added token formats to question – Ashish Patil Apr 10 '17 at 06:57
  • Thanks. Cool for censoring portions of it. Okay, so I think the main issue here *is* because of the old token. New token formats have a `:` (semi-colon). My guess is that the `InvalidTokenVersion` error is somehow similar to `InvalidRegistration`, where you'll have to delete the corresponding token and [get a new (and current) registration token](https://firebase.google.com/docs/cloud-messaging/ios/client#retrieve-the-current-registration-token) compatible with FCM. – AL. Apr 10 '17 at 07:03
  • 1
    @AL. But my problem is that I will have to wait and release new version of application with compatible FCM SDK integrated and wait for all my users to version update, and not everyone updates. It should have been straight forward to import existing working GCM tokens, and get new working FCM compatible tokens. If importing is possible with APNS which is totally different format managed by iOS, doing it for Google's own tokens seems logical, There must be some way to do it. – Ashish Patil Apr 10 '17 at 07:30

1 Answers1

1

GCM library included 2 different APIs to generate GCM tokens:

GoogleCloudMessaging.register() // Deprecated in 2015
InstanceID.getToken()

Unfortunately tokens generated with the first API are not supported by the Topics API (both in GCM and FCM).

BathAdd API is part of the InstanceId / Topics API.

I understand this is not ideal, unfortunately the best option is to update the application to use GCM InstanceId.getToken() or FCM.

Diego Giorgini
  • 12,489
  • 1
  • 47
  • 50