According to this:
"Starting from March 2020, FCM stopped creating legacy server keys. Existing legacy server keys will continue to work, but we recommend that you instead use the newer version of key labeled Server key in the Firebase console. "
They have updated the REST API to send messages to a device.
This is my code:
But this error comes:
what am I doing wrong?
"Starting from March 2020, FCM stopped creating legacy server keys. Existing legacy server keys will continue to work, but we recommend that you instead use the newer version of key labeled Server key in the Firebase console. "
They have updated the REST API to send messages to a device.
This is my code:
Build app server send requests | Firebase Cloud Messaging
firebase.google.com
B4X:
'To send to a single, specific device, pass the device's registration token as shown.
'See the client setup information for your platform to learn more about registration tokens.
'https://firebase.google.com/docs/cloud-messaging/send-message#send-messages-to-specific-devices
Public Sub SendMessagesToSpecificDevices(token As String,body As String,title As String)
Dim url As String = $"https://fcm.googleapis.com/v1/projects/${PROJECT_NAME}/messages:send"$
Dim json As JSONGenerator
json.Initialize(CreateMap("message":CreateMap("token":token,"notification":CreateMap("body":body,"title":title))))
Dim j As HttpJob : j.Initialize("",Me)
j.PostString(url,json.ToString)
j.GetRequest.SetContentType("application/json")
j.GetRequest.SetHeader("Authorization", "Bearer " & API_KEY)
Wait For (j) JobDone(j As HttpJob)
End Sub
B4X:
ResponseError. Reason: , Response: {
"error": {
"code": 401,
"message": "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
"status": "UNAUTHENTICATED"
}
}