B4J Question Send Firebase Push Notifications to single token

Schakalaka

Active Member
Licensed User
Hello, i have modify the sender of this topic for send the push notification to a single user.
but it return AUTH PROBLEM:

B4X:
{
    "message": {
        "data": {
            "title": "this is the title",
            "body": "And this is the body"
        },
        "token": "BBwKpj1Cv-mO_zHsV9HE_uOuwPF1pqz6He-lfwifEgHmPVheACHSoSCRUeYCvka7m0elRvJRC8JtltNJlYbe7bY"
    }
}
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"
  }
}

The code used is this:

B4X:
#AdditionalJar: google-auth-library-oauth2-http-1.18.0.jar
#AdditionalJar: google-auth-library-credentials-1.18.0.jar
#AdditionalJar: guava-23.0.jar
#AdditionalJar: google-http-client-1.43.3.jar
#AdditionalJar: google-http-client-gson-1.43.3.jar
#AdditionalJar: gson-2.10.1.jar
#AdditionalJar: opencensus-api-0.31.1.jar
#AdditionalJar: opencensus-contrib-http-util-0.31.1.jar
#AdditionalJar: grpc-context-1.27.2.jar
#PackagerProperty: AdditionalModuleInfoString = uses com.google.auth.http.HttpTransportFactory;

Sub Process_Globals
    Private Const ProjectId As String = "click-And-claim-bitcoin" ' Cambia con il tuo ID del progetto Firebase
End Sub

Sub AppStart (Args() As String)
    Dim UserToken As String = "BBwKpj1Cv-mO_zHsV9HE_uOuwPF1pqz6He-lfwifEgHmPVheACHSoSCRUeYCvka7m0elRvJRC8JtltNJlYbe7bY" ' Inserisci il token del destinatario manualmente
    SendToSingle(UserToken, "this is the title", "And this is the body")
    StartMessageLoop
End Sub

Private Sub SendToSingle(userToken As String, Title As String, Body As String) As ResumableSub
    Dim Job As HttpJob
    Job.Initialize("", Me)
    Dim data As Map = CreateMap("title": Title, "body": Body)
    Dim message As Map = CreateMap("token": userToken, "data": data)
   
    Dim jg As JSONGenerator
    jg.Initialize(CreateMap("message": message))
    Log(jg.ToPrettyString(4))
   
    Job.PostString("https://fcm.googleapis.com/v1/projects/" & ProjectId & "/messages:send", jg.ToString)
    Job.GetRequest.SetContentType("application/json;charset=UTF-8")
   
    ' Inserisci il tuo token di accesso manualmente
    Dim AccessToken As String = "BBwKpj1Cv-mO_zHsV9HE_uOuwPF1pqz6He-lfwifEgHmPVheACHSoSCRUeYCvka7m0elRvJRC8JtltNJlYbe7bY"
    Job.GetRequest.SetHeader("Authorization", "Bearer " & AccessToken)
   
    Wait For (Job) JobDone(Job As HttpJob)
    If Job.Success Then
        Log(Job.GetString)
    End If
    Job.Release
    Return True
End Sub

Sender ID: 963102783637
Cloud Messaging API (Legacy): AAAA4D1mOJU:APA91bF6bKkvZeBje5y4A6vQJkHUANN_9hNUPhxgiXUbm2EOp1lIRNTCeVH5xdcBEnn2xlLtIDr4eHQ4gPUGRZDl0vWCTgIv6Y8pNdaIwpRtodoeovZe-ADMqDpX7e6C0wmOdZtSIkVI

User token: cd6FFqsmTy2vWxN_3PGBLG:APA91bF1fd4JLotlv6EWmYhQXJUMCzTFNxAHUf1rY75pFzNLQZUT53HbIThiUj00fcFfjTlbvldIuk5eFwMka8J3IB3BMiJcfaGqd-zJpwqgWQ1HN6ha5_DC47gVHDcGF8DCR-4j2Tb1

Web Push certificates: BBwKpj1Cv-mO_zHsV9HE_uOuwPF1pqz6He-lfwifEgHmPVheACHSoSCRUeYCvka7m0elRvJRC8JtltNJlYbe7bY

on b4a app, i find the firebase token with
B4X:
 fm.Token

Thank you
 
Top