Android Question Firebase Notifications - Time limits on sending updates to a device?

Haris Hafeez

Active Member
Licensed User
Longtime User
Hello All,

This one seems a little strange. I have an app where the server can send status updates about a specific item to a specific device. I am storing Firebase tokens and using them in the 'to' data field as documented by Firebase. This works well until I test the scenario of sending multiple updates within, say, 10-15 seconds of each other. To my mind, this is perfectly valid scenario. The client can have multiple items listed in which it is interested in receiving status updates for (say stock quotes). Why would firebase limit pushing out updates?

The response I receive from Firebase is below:

'The request was missing an Authentification Key (FCM Token)'

Why does this happen? Can anyone shed some light on this please? My device is Nexus 5X running 7.1. Do note that subsequent calls, after about a minute or so will succeed in sending the update through push.

Thanks,
Haris
 

Haris Hafeez

Active Member
Licensed User
Longtime User
Thanks for your response. I believe I have got the latest libraries and other required packages. I am simply getting an error HTML in return if I attempt to send another message using the same server key. I am not sure what is happening.

I am not sure I have yet grasped the concept of collapsible vs non-collapsible messages. I have simply taken the FCM sample and integrated into my app. This is an annoying issue to say the least as it is not giving me much information to chew on.

[UPDATE] - It appears the messages we send are non-collapsible as these are data messages instead of notification messages.
 
Last edited:
Upvote 0

Haris Hafeez

Active Member
Licensed User
Longtime User
OK. I might be missing something here but why do we need the collapse key given data messages are non-collapsible? Or are our messages collapsible?
 
Upvote 0

Haris Hafeez

Active Member
Licensed User
Longtime User
Upvote 0

Haris Hafeez

Active Member
Licensed User
Longtime User
OK. I have done a few tests using Postman on Chrome and this problem *does not* happen when using postman.
I have also tested sending the messages from a new B4J command line program and quite oddly, this *does not* happen from the B4J program (essentially the FCMPush example). I ran this program on Windows.

Hence, I am now starting to wonder if it has something to do with either my web app written in B4J (one of the handlers in the web app is responsible for sending out push updates) OR it is because of me running my web app server on a Linux environment (an Amazon Linux AMI on EC2).

[UPDATE] - I ran the test B4J program on my Amazon Linux instance and it again works as expected. I am now wondering what exactly is happening inside the Jetty server that it fails?
[UPDATE 2] - I can now also confirm that the issue is when I push notifications from the web app BUT from within a Handler class. This is what is causing issues. I tried by pushing multiple messages from the Main module in the B4J app server and that does send multiple push messages out to the device.

So I have to ask, what is causing this behaviour?

The only error I get is the one attached below. I am running out of ideas how to resolve this. I'll greatly appreciate any help. Otherwise it looks like I will have to investigate using other push mechanisms (like the old GCM).

Thanks.

<HEAD>
<TITLE>The request was missing an Authentification Key (FCM Token). Please, refer to section &quot;Authentification&quot; of the FCM documentation, at https://firebase.google.com/docs/cloud-messaging/server.</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>The request was missing an Authentification Key (FCM Token). Please, refer to section &quot;Authentification&quot; of the FCM documentation, at https://firebase.google.com/docs/cloud-messaging/server.</H1>
<H2>Error 401</H2>
</BODY>
</HTML>
 
Last edited:
Upvote 0

Haris Hafeez

Active Member
Licensed User
Longtime User
We cannot guess. Where is the code that sends the messages?
Attached here is a B4J web app that sends push messages every time a request hits /push endpoint. Do note that just by running one or two times you will not witness the error. Try it a few time by hitting the refresh on browser and you will eventually see that error. It appears randomly and you may see it straightaway after you run it a couple of times or you may need to run the test (click refresh) a few times.

Forgot to mention I am testing on Linux.
 

Attachments

  • FCMPushServer.zip
    2 KB · Views: 208
Upvote 0

KMatle

Expert
Licensed User
Longtime User
Upvote 0

Haris Hafeez

Active Member
Licensed User
Longtime User
What I see is a missing UTF-8 in the content type header.

Please try:

B4X:
Job.GetRequest.SetContentType("application/json;charset=UTF-8")
I did not try appending the encoding to the content type header, but I used the following in my code and that did not work either. I think they are equivalent but will try your suggestion as well.
B4X:
Job.GetRequest.SetContentEncoding("UTF-8")
 
Upvote 0

Haris Hafeez

Active Member
Licensed User
Longtime User
I am wondering if there is a way to print the request payload just before it is sent over to the server? So we can see what exactly are the http headers and the body of the post when it is sent over.
 
Upvote 0

tigrot

Well-Known Member
Licensed User
Longtime User
I don't use notifications, only data payloads. I send a packet every 30" and nothing happened in months. I use a TTL of a few seconds so no packet is held in queue. I can afford to loose some packet, but luckily this don't happens.
 
Upvote 0

Haris Hafeez

Active Member
Licensed User
Longtime User
I don't use notifications, only data payloads. I send a packet every 30" and nothing happened in months. I use a TTL of a few seconds so no packet is held in queue. I can afford to loose some packet, but luckily this don't happens.
Is your server-side app a B4J app running on JVM/Jetty and the OS Linux?
I have found that if I send my push messages in other ways, it does not happen. I have tested this with sending push messages from another B4A app and I do not see this issue.
 
Upvote 0

Haris Hafeez

Active Member
Licensed User
Longtime User
It doesn't matter.

Start with using the exact code from the tutorial: https://www.b4x.com/android/forum/t...-messages-firebase-cloud-messaging-fcm.67716/
and send to a topic.

It should work.
Sending to a topic will not satisfy my requirement, which is to notify a user of their particular item of concern. Think about a stock portfolio. If there is a significant movement in some stocks in a given portfolio, I will send a reply to that particular user, not to the entire user universe, which is what a topic will do. Are you suggesting I should create a unique FCM topic for each registered user? This could work but I haven't implemented it and not sure if there will be a limit on topics (though I can't seem to find it in FCM docs).
I use JVM on Windows 10(or 7). OS shouldn't do any difference, it'a a simple WEB command, the basis of all new OS's.

OS does make a difference specially when dealing with Strings. Also, JVM itself may behave in a slightly different way based on the OS so I wouldn't rule it out. But I tend to agree with you that for the most part (and in fact sending a simple post request here) should not cause any issues. I am only trying to rule things out.

Thanks for all your input guys.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

yiankos1

Well-Known Member
Licensed User
Longtime User
OK. I have done a few tests using Postman on Chrome and this problem *does not* happen when using postman.
I have also tested sending the messages from a new B4J command line program and quite oddly, this *does not* happen from the B4J program (essentially the FCMPush example). I ran this program on Windows.

Hence, I am now starting to wonder if it has something to do with either my web app written in B4J (one of the handlers in the web app is responsible for sending out push updates) OR it is because of me running my web app server on a Linux environment (an Amazon Linux AMI on EC2).

[UPDATE] - I ran the test B4J program on my Amazon Linux instance and it again works as expected. I am now wondering what exactly is happening inside the Jetty server that it fails?
[UPDATE 2] - I can now also confirm that the issue is when I push notifications from the web app BUT from within a Handler class. This is what is causing issues. I tried by pushing multiple messages from the Main module in the B4J app server and that does send multiple push messages out to the device.

So I have to ask, what is causing this behaviour?

The only error I get is the one attached below. I am running out of ideas how to resolve this. I'll greatly appreciate any help. Otherwise it looks like I will have to investigate using other push mechanisms (like the old GCM).

Thanks.

<HEAD>
<TITLE>The request was missing an Authentification Key (FCM Token). Please, refer to section &quot;Authentification&quot; of the FCM documentation, at https://firebase.google.com/docs/cloud-messaging/server.</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>The request was missing an Authentification Key (FCM Token). Please, refer to section &quot;Authentification&quot; of the FCM documentation, at https://firebase.google.com/docs/cloud-messaging/server.</H1>
<H2>Error 401</H2>
</BODY>
</HTML>
If someone has same problem as Haris describes, just put Sub at Main module and use CallSubDelayed(Main,"send") from Handler class. This way every notification will arrive and will not show error message about Authentification Key (FCM Token).
I solved it with this workaround.
 
Upvote 0
Top