B4J Question Firebase Error

Declan

Well-Known Member
Licensed User
Longtime User
I have a app in B4j that handles communication from remote devices.
I then send a notification with Firebase to a B4a app with the following code:
B4X:
public Sub SendMessage(Topic As String, Title As String, Body As String, Data As Map) As ResumableSub
    Dim sdeviceID As String = Data.get("deviceid")
    Dim smsgType As String = Data.get("msgtype")
    Dim smsgdate As String = Data.get("msgdate")
    Dim sVoltage As String = Data.get("voltage")
    '
    smsgdate = NiceDate(smsgdate)
    Dim stitle As String = GetMessageTitle(sdeviceID, smsgType)
    Dim sBody As String = stitle & ", voltage @ " & sVoltage & ", on " & smsgdate
   
    Dim m As Map = CreateMap("to": $"/topics/${Topic}"$)
    Data.Put("topic", Topic)
    Data.Put("title", stitle)
    Data.Put("body", sBody)
    If Topic.StartsWith("ios_") Then
        Dim iosalert As Map =  CreateMap("title": stitle, "body": sBody, "sound": "default", "icon": "./assets/appicon.png")
        m.Put("notification", iosalert)
        m.Put("priority", 10)
    Else
        Dim pri As Map = CreateMap("priority":"high")
        m.Put("priority", "high")
        m.Put("android", pri)
    End If
    m.Put("data", Data)
   
    Dim jg As JSONGenerator
    jg.Initialize(m)
    '
    Dim msgOut As String = jg.ToString
    Log(msgOut)
   
    Dim j As HttpJob
    j.Initialize("fcm", Me)
    j.PostString("https://fcm.googleapis.com/fcm/send", msgOut)
    J.GetRequest.SetContentType("application/json;charset=UTF-8")
    J.GetRequest.SetHeader("Authorization", "key=" & API_KEY)
    Wait For (j) JobDone (j As HttpJob)
    If j.Success = True Then
        ' Reply from Firebase
        Dim jp As JSONParser
        jp.Initialize(j.GetString)
        Dim rp As Map = jp.NextObject
        Dim message As String = rp.Get("message_id")
        'this is important for the associations related content
        'convert the map to an array of objects
        Data.Put("msgid", message)
    Else
        Data.Put("msgid", "")
        Log(j.ErrorMessage)
    End If
    j.Release
    Data.Put("status", "A")
    Return Data
End Sub

This has worked flawlessly, but I now get the following error on my B4j app:
B4X:
ResponseError. Reason: , Response: {"error":"Deprecated endpoint, see https:\/\/firebase.google.com\/docs\/cloud-messaging\/migrate-v1"}
{"error":"Deprecated endpoint, see https:\/\/firebase.google.com\/docs\/cloud-messaging\/migrate-v1"}

I have looked at "https:\/\/firebase.google.com\/docs\/cloud-messaging\/migrate-v1"
But cannot see what requires any changes.
 

DonManfred

Expert
Licensed User
Longtime User
Upvote 0
Top