Push Notification Automate Using PHP using the Firebase service. error: “InvalidRegistration”

I’m trying to create Push Notification Automate Using PHP in Ionic2 Type Script Android application.

I use my Server Key taken from my Firebase Project Settings/Cloud Messaging/Project credentials/Key/Server Key/Token in YOUR-API-ACCESS-KEY-GOES-HERE below in sendPushNotification.php located on my server.

and I got function to send notification:

passed to reg variable as string without registrationId: xxxxx, but I also have tried send it as json string and adding of json = array();.

This way string is incorrect, so I send it just as string. Console result shows my token properly, without missed or extra chars or marks:

XHR finished loading: GET "myserver/php/sendPushNotification.php?token={ my token }".

First of all, in sendPushNotification.php I’ve tried:

curl_setopt( $ch,CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send' );

because my registrationType: "FCM"

and also:

curl_setopt( $ch,CURLOPT_URL, 'https://android.googleapis.com/gcm/send' );

but in both cases result is {error: “InvalidRegistration”}:

Except that the GCM are deprecated, but still works here Implementing an HTTP Connection Server also it says in Checking the validity of a server key article.

But I’m not sure, if it is a reason of particular error

Please check with both the side app side and your side that the exact same registration id is stored in the server which Application on mobile receives it in on onTokenRefresh method. You should have received the exact same registration token.

Firebase has three message types:

Notification messages: Notification message works on background or foreground. When app is in background, Notification messages are delivered to the system tray. If the app is in the foreground, messages are handled by onMessageReceived() or didReceiveRemoteNotification callbacks. These are essentially what is referred to as Display messages.

Data messages: On Android platform, data message can work on background and foreground. The data message will be handled by onMessageReceived(). A platform specific note here would be: On Android, the data payload can be retrieved in the Intent used to launch your activity.

Messages with both notification and data payloads: When in the background, apps receive the notification payload in the notification tray, and only handle the data payload when the user taps on the notification. When in the foreground, your app receives a message object with both payloads available. Secondly, the click_action parameter is often used in notification payload and not in data payload. If used inside data payload, this parameter would be treated as custom key-value pair and therefore you would need to implement custom logic for it to work as intended.

In your case, this is an issue of token received from firebase, is may be modified or broken while sending to server.



Thank you for your answer, problem solved