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 :)
Related
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.
I have a very weird issue in my android app that uses GCM for sending notifications to the user.
Initially, I created a new project on Google console and activated the GCM API. I added the JSON file into my app and my server was sending the notification with the provided API key.
Few days back, I created a new project under a new account. So I got a new JSON file and a new API key for server. I added the new JSON file in my app and added the new API key in my server script. But the issue is, some devices get the notifications with the new key but for some devices, I still need to send the notification using the old API key. These devices have the updated application installed on them.
I am not able to figure why is this happening. I am planning to migrate to FCM soon but still I would like to figure out the reason behind such behavior if in case it repeats in the future.
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.
I am using gcm in my application.
In Google Developers Console page, I created a project and obtained a project id:
Using this project id in my application, the user gets registered to the gcm servers and obtain a registeration id. Then it is sent to my 3rd party server to be stored.
When 3rd party server wants to send message to the user, it uses the apikey I've obtained in the Google Developer Console page in the header of the post action and uses ther registeration id that has been stored for this particular user. The api key I'm using is from:
Please note that it's the key for server applications and the way i'm using this information is as just as I explained.
Everything works fine, messages are retrieved by the correct users and so on.I'm planning to deploy my app on google play but what is written in the section:GCM advanced topics confuses me. it says :
When an application is updated, it should invalidate its existing registration ID, as it is not guaranteed to work with the new version
and on the comment section of the sample code in Implementing GCM client sample code there is this comment:
// Check if app was updated; if so, it must clear the registration ID
// since the existing regID is not guaranteed to work with the new
// app version.
What is meant by these two explanations? I thought unless I press regenerate key here:
my api key wouldn't change. Why should it (or does it really) change when I update my application? or am I getting something wrong?
You are mixing between two different terms - API key and Registration ID. You don't have to create a new API key when deploying a new version.
What Google recommend to do (in the quotes you included above) is to re-register each device that installs the new version to GCM (and not rely on a previously obtained Registration ID), because the existing Registration ID assigned to the device for your application is not guaranteed to work for the new version of the app.
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/