1

In GCM was feature to create new API key, so on my current project different keys were used for staging and prod environment. But now according to info from here new keys created for GCM are not valid.

How can I create few FCM keys for one project?

Pavlo I.
  • 117
  • 3
  • 11

2 Answers2

3

For GCM or FCM, you'll be needing a Server Key. Steps are below on how to Create a New or Import a project to have a valid Server Key.

If you are just starting to use GCM, instead of creating a project in the Google Developers Console, do it in the Firebase Console. After creating the project, simply use the auto-generated Server Key. Here are the steps where to find the Server Key:

  1. Go to your Firebase Console and click on CREATE NEW PROJECT.
  2. Fill in your desired Project Name and select your Country. After this, the new Project should be active.
  3. Then on left-side panel, click on the gear button and select Project Settings.
  4. Then go to the Cloud-Messaging Tab.

For old GCM projects, you can simply Import the project to the Firebase Console:

  1. Go to your Firebase Console and click on IMPORT PROJECT.
  2. Select the project you want to import and your country.
  3. Click on ADD FIREBASE. After this, the new Project should be active.
  4. Then on left-side panel, click on the gear button and select Project Settings.
  5. Then go to the Cloud-Messaging Tab.

Portion taken from my answer here.

Community
  • 1
  • 1
AL.
  • 36,815
  • 10
  • 142
  • 281
  • Project already imported. Thing here that this project contains FCM key, that used by our app server to send notifications. I need to create not new project but only key. – Pavlo I. Dec 01 '16 at 11:07
  • @PavloI. Why do you need a new Server Key? The idea here is that using a single Server Key should be enough, unless you're going to create a different project (*which you don't want to*). Or are you looking to [regenerate the Server Key](http://stackoverflow.com/a/37741826/4625829)? – AL. Dec 01 '16 at 12:50
  • It is an requirement to decouple different environments. But if it is not supported by FCM seems we'll use single token for all. – Pavlo I. Dec 05 '16 at 09:53
  • I think you are referring to having separate Sender IDs for staging and prod environment, not an API key, like what was mentioned in the [XMPP docs](https://developers.google.com/cloud-messaging/ccs#connecting): *...should use a different GCM sender ID to avoid any risks of sending test messages to production users or sending upstream messages from production traffic over test connections.* For that case, creating a separate project is the way to go. – AL. Dec 05 '16 at 10:09
0

To add upon needing separate keys for both development and prod, once you create a new firebase project for your other environment, you'll have a new google-services.json file to incorporate with the new keys. At this point you can have your production google-services.json file in the app/src/release directory to keep them separate. More info here:
https://developers.google.com/android/guides/google-services-plugin

Robin Schaaf
  • 145
  • 1
  • 11