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.
Related
I have a mix of GCM and FCM Server API keys that belong to different android apps. However I am not the owner of the apps and do not have direct access to the google developer console.
Is there a way to detect whether a Cloud Messaging Server API key is enabled for Firebase?
I would like to know this so that I can notify the owners of the GCM server keys to update to Firebase.
Thanks
-David
There is no way to tell if a Server Key used in the request is from a GCM/FCM enabled project. There is RemoteMessage.getFrom() which gives the Sender ID of the sender or to identify which topic the message was sent to, but it doesn't give any other details.
While on the matter, I'm fairly sure that there is even no way for you to retrieve the value of the Server Key that was used by the Sender in the first place.
With all that said, so long as it is a valid Server Key, it should be compatible to use for both GCM and FCM. From what I've experienced, I had a Server Key originally generated from my Developer Console, and after I imported the project to Firebase, the Server Key that appeared in the Cloud Messaging tab was still the same (I'm not so sure if that's still the case though).
Nonetheless, Server Key used for GCM should still be compatible for FCM.
How to register a new Server key in the GCM after September 2016?
Yes, I understand that the registration of new keys in the GCM is prohibited.
Starting from September 2016, you can create new server keys only 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.
But our company policy does not allow the use of FCM.
Perhaps Google office can help?
There is no other way to generate a valid Server key to use for GCM or FCM, other than using the one auto-generated one when you create/migrate a Firebase Project in the Firebase Console.
As mentioned in the comments, using a Server Key retrieved from the Firebase Console can still be used by implementations for GCM. Using this technically doesn't mean that you're using FCM already.
Also mentioned in the comments, FCM is practically just GCM itself with new features. It is already strongly recommended that users of GCM migrate to using FCM already.
If you're still persistent on not using a Server Key from generating a Firebase Project, I suggest contacting GCM Support through this form, providing the details as to why you need to generate a new Server Key.
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 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/
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/