How to use an existing GCM token within another Firebase project?

流过昼夜 提交于 2019-11-28 07:46:57

When sending messages from your back-end server, you need to authenticate the request with the API-KEY associated with project (sender-id) used to generate the GCM/FCM token.
Due to security restrictions here are no workaround for this.

For existing GCM users the best migration consists in importing the old project into the Firebase Console. This will allow you to target both old and new client, since the sender-id will not change
Steps here: https://developers.google.com/cloud-messaging/android/android-migrate-fcm

If that is not option (you have already created a new Firebase Project distinct from the previous Google Cloud Project) you have two possibilities:

  1. Easier and recommended approach: change your back-end to store which client originated the gcm/fcm token. Then use the correct API-KEY when sending messages from your back-end. (the API-KEY associated to the old project for old clients, and the new API-KEY for new clients that are using the new Firebase project).

  2. If you cannot change your back-end at all: in FCM you can create an additional token for the old SenderID, using the API:
    FirebaseInstanceId.getInstance().getToken("old-sender-id", "FCM")
    Because this token is associated to the old-sender-id your back-end will be able to send messages to it using the API-KEY of the old project.
    Note: this doesn't affect the Firebase Console which is based on the new-sender-id.
    That console will be able to target only the new clients that are including the firebase sdk and the associated google_services.json file.

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