New Firebase cloud messaging server key keeps changing every week - android

The server key for cloud messaging under
Project Settings -> Cloud Messaging -> Server Key
keeps changing frequently, about once a week.
This is extremely frustrating. Our notification server calls fail with an error code of 401, which means it's an authorization problem.
But once I update the server key on my backend, with the key i see on the firebase console, which is different each time after this 401 authorization error, all works fine.
I have Googled my best on this, but there is no documentation, or support available for this error. Is this meant to change so much? If so, how can i update the SERVER_KEY automatically on my end..? Is there a REST API for this?

I asked directly to the Firebase Support with an issue similar to the one you have and they told me:
If someone changes the server API key in Google API console, the server API key will also be changed in Firebase console. Firebase does not change your server API key without notifying you. Make sure no one has changed your server API key in Google API console recently and that the Server API key is the same in both the consoles.
A change in my API Key occurred only once in the time I have been using Firebase. So maybe you could contact the Firebase support or try to check if someone is changing the key in the Google API console.

Google Firebase mostly sends you an email about upgrading their serve keys. when you receive such emails , quickly visit and update your scripts with your new key in the console. this can happen weekly or monthly, not really structured.

Related

How can recover the GCM API key? or know which account have the GCM API key?

I have a problem with the GCM API.
I have an application developed by other person in my company a few months ago and he is no longer working in the company, the problem is that in this moment the GCM API is response with the error “Invalid (legacy) Server-key delivered or Sender is not authorized to perform request”, I found that this error occurred because the key is deleted but I don’t know with which account was created this key and I can’t change the key by a new key because I need send a notification to all devices and the new key require that the devices to be registered again.
How can recover the key? or know which account have the key?
Thanks.
AFAIK, you can't recover the Server Key. The Invalid Legacy Server Key doesn't signify that the key was deleted, it's just that you're using an old API key (see my answer here) and should use the Server key with a new format -- this is automatically generated by importing the corresponding project to Firebase, then going to the Project Settings > Cloud Messaging tab.
The tokens are not tied to the Server Key, it is only used for authorization when sending the messages. The tokens are instead, tied to the corresponding Sender ID.
If you have no way of identifying which project owns it, you should reach out to Firebase Support directly, providing as much details as you can.

Google Cloud Messaging tutorial - messages don't send

I'm following Google Cloud messaging tutorial, I'm not exactly understang phrase:
First, make sure your Server key (not the client API key in googleservices.json) is provided as the value of API_KEY in GcmSender.java.
So in order to run this sample, I need to write a server side? I thought that GcmSender.java already emulates server side of the application? Can someone clarify it?
As #MohanadMohie you should instead use FCM.
First, make sure your Server key (not the client API key in googleservices.json) is provided as the value of API_KEY in GcmSender.java
The GcmSender.java does emulate the function for sending a message. This only states that you should make sure that the API key you use is a valid Server Key.
And as per Server Keys go, there is already a note in the GCM docs saying:
Starting from Sept. 2016 new server key can only be created in the Firebase Console using the Cloud Messaging tab of the Settings panel. Existing projects that need to create a new server key can be imported in the Firebase console without affecting their existing configuration.
Plus, in FCM, you'll be able to make use of the Firebase Console to send push notifications.

GCM - How to Generate a Server API Key For Android Push Notification

I want to use push notification service on my Android project, but when I try to generate a server key, I notice that Google's developers console changed and I can't find where I can generate my server key. I looked at a lot of tutorials but still I can't do it.
Update: There is now a visible note in the GCM docs saying:
Starting from Sept. 2016 new server key can only be created in the Firebase Console using the Cloud Messaging tab of the Settings panel. Existing projects that need to create a new server key can be imported in the Firebase console without affecting their existing configuration.
Just retrieved a part of my answer here.
Go to your Google Developers Console
On the left-pane, click on Credentials
Under the Credentials Tab, Click on Create Credentials
Select API Key
Select Server Key
Fill out the details.
Click on Create
The Server Key should be available by then.
PS: Just tried it out, this still is a way to generate a Server Key.
please consider changing from google cloud messaging to firebase cloud messaging
google now recommend developers to use FCM instead of GCM
link here: https://firebase.google.com/features/

GCM new server key - What to do with old server key?

Today I implemented the new GCM flow in one of our apps which has been on the market for several years already and uses the old GCM. I must have missed when they changed it in October.
So I did all the stuff that had to be done, registered the app in the Google API console, downloaded the google-services.json and so I also generated a new server API key.
Now this new server API key works fine with the new GCM flow, but in our backend there is still the old server key which still works for the user with the currently released app.
So what do we do now? Just replace the old server key and hope the users will update the app? Or put in some condition depending on app version?
What is the best way to handle this transition?
Thx in advance :)

GCM HTTP Error 401: Unauthorized

I have integrated GCM on client also made its Server side component. Every thing was working fine, I was able to send push notification from server to all the registered client. I am using google App engine as my server.
Problem came when:
I changed the API Key on server.
Earlier I was using my personal GMail account to get API Key and all other access was through my account. Just before pushing the application live I moved the server to Production account and also changed the IDs as per production Ids. By Id I mean API Key, project ID, Production Keystore etc. Now the issue is when I want to send Push notification on Server I am getting URL Exception "HTTP Error 401: Unauthorized"
I tried doing:
- Deleting my older Ids.
- Deleting Old Public API access keys.
The same code works fine if I try to send Push notification from my old Server.
Does it has something to do with : Project package name and API key... which gets registered once can only be used....If yes How to delete that without changing the client project package name.
Please help we cannot go live with Old Server.
Check if ports 5228-5230(GCM ports) are open in the new server. It could be the problem.
The issue can be beacause you are using the old server api key for the new server as well. For sending the push notification from server side, you need the api key generated with the help of server's public IP address.
If it is testing purposes, make sure your server API key on the google console has the relevant ip addresses in the whitelist:
0.0.0.0/0
::/0
These are for ipv4 and ipv6 ips
Since this is an older question that was never answered but still gets views, I'll post here that this issue may have been obsoleted as the Cloud Console has gone through a couple of iterations since then.
Also, Google Cloud Messaging has been superseded by Firebase Cloud Messaging. New projects should use FCM, and existing projects are encouraged to upgrade in order to benefit from new features.
Firebase Cloud Messaging
https://firebase.google.com/docs/cloud-messaging/

Categories

Resources