B4J Question FCMPush Authentication issue

Discussion in 'B4J Questions' started by MarcelloCSI, Dec 13, 2017.

  1. MarcelloCSI

    MarcelloCSI Active Member Licensed User

    I would like to send notification to specific device with the B4J server. I have the Firebase token of the destination device.

    I'm in trouble with Firebase authentication.

    This is the code, FCMPush with little variation:
    'Non-UI application (console / server application)
    #Region  Project Attributes
    #MergeLibraries: True
    #End Region

    Sub Process_Globals
    Private const API_KEY As String = "AAAArE0gcBE..."  
    Private myToken As String = "eiTAn3c39UU..."
    End Sub

    Sub AppStart (Args() As String)
    "This is the title""Hello!!!!")
    End Sub

    Private Sub SendMessage(Token As String, Title As String, Body As String)
    Dim Job As HttpJob
    "fcm", Me)
    Dim m As Map = CreateMap("token": Token)
    Dim data As Map = CreateMap("title": Title, "body": Body)
    "data": data)
    Dim jg As JSONGenerator
    "https://fcm.googleapis.com/v1/projects/myapplication****-78ecd/messages:send", jg.ToString)
    "Authorization""key=" & API_KEY)
    'Job.GetRequest.SetHeader("Authorization", "Bearer " & API_KEY)
    End Sub

    Sub JobDone(job As HttpJob)
    If job.Success Then
    End If
    '<-- non ui app only
    End Sub
    This is the error:
    Waiting for debugger to connect...
    Program started.
    "error": {
    "message""Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
    [jobname=fcm, success=false, username=
    , password=, errormessage=Unauthorized, target=class b4j.example.main
    , taskid=1, req=anywheresoftware.b4h.okhttp.OkHttpClientWrapper$OkHttpRequest@50134894, tag=java.lang.Object@2957fcb0
    , httputils2service=null]
    Program terminated (StartMessageLoop was not called).
    Can someone help me?

    Thanks in advance
  2. Erel

    Erel Administrator Staff Member Licensed User

    It is not a server. It is a command line program.

    Where does this link come from? You don't need to change the link. Just the "to" value in the map.
  3. MarcelloCSI

    MarcelloCSI Active Member Licensed User

    Yes, it is not a server. i was thinking of it beacouse i have to integrate it in a server.

    I changed the link, i thought that "https://fcm.googleapis.com/fcm/send" had to be changed with the application that need that service.

    Now it is working. Thanks very
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice