Android Question Firebase notification

stari

Active Member
Licensed User
Longtime User
I try to send firebase notification with B4J. But i get this in "Logs":
Waiting for debugger to connect...
Program started.
<HTML>
<HEAD>
<TITLE>Unauthorized</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>Unauthorized</H1>
<H2>Error 401</H2>
</BODY>
</HTML>
[jobname=fcm, success=false, username=
, password=, errormessage=Unauthorized, target=class b4j.example.main
, taskid=1, req=anywheresoftware.b4h.okhttp.OkHttpClientWrapper$OkHttpRequest@394576, tag=java.lang.Object@1ff5160
, httputils2service=null]
Program terminated (StartMessageLoop was not called).

From Firebase conslole i can send notifications, but i get null,null.
 

Attachments

  • Push.zip
    1 KB · Views: 175

derez

Expert
Licensed User
Longtime User
Checked the application with my API-Key and it works, so check your key, since you get success=false
 
Upvote 0

inakigarm

Well-Known Member
Licensed User
Longtime User
This example works for me with the correct Firebase API key; have you created one for your project?

B4X:
Waiting for debugger to connect...
Program started.
[jobname=fcm, success=true, username=
, password=, errormessage=, target=class b4j.example.main
, taskid=1, req=anywheresoftware.b4h.okhttp.OkHttpClientWrapper$OkHttpRequest@6f9127b5, tag=java.lang.Object@33d1e090
, fx=anywheresoftware.b4j.objects.JFX@77f2603a, httputils2service=null]
{"message_id":7063600572190184714}
 
Upvote 0

stari

Active Member
Licensed User
Longtime User
Yes , i have API key. From firebase conslole i can send notifications.
But,...what must i write for "Authenticarion"?

 
Upvote 0

stari

Active Member
Licensed User
Longtime User
Have you add the SHA1 certificate fingerprint from B4A app ? (Tools --> Private Sign Key)

View attachment 49431


View attachment 49430
Thks for help
All done as you write, but still success = false
On other side, i can send notifications from Firebase console.
Can you try with my Firebase console ?
user: elfemmit@gmail.com
pass: 1Vrtnica321

in B4A:
Packkage: com.elfemmit

Certificate fingerprints:
MD5: B8:83:53:67:20:3D:20:AF:32:73:8B:3B:8E:06:E4:3E
SHA1: E9:61:3C:E7:44:1C:0E:CD97:18:E8:94:23:82:28:EE:EB:9B:3B
SHA256: 90:30:FB:19:FA:9D:29:23:C0:A4:CF:54C:87D:0C:88:5C:10:3E:035:67:BE:96:9C:22:E9:62:03:BB:32
Signature algorithm name: SHA1withDSA
Version: 3

I can later change my pass, but for testing i think is no problem.

regards

Stari
 
Upvote 0

inakigarm

Well-Known Member
Licensed User
Longtime User
Well, it seems that the pwd is not correct


I don't know exactly which will be the error, but I remember have configured Firebase and a B4A app with the Firebase tutorial from Erel without problems.
Maybe you have to follow the tutorials step by step
 
Upvote 0

stari

Active Member
Licensed User
Longtime User
Sory, typo was here.
pass: 123Vrtnica321

And, i have make my Firebase and B4A app drom Erels tutorial, not only onw time.
What i make wrong ?
I don't know!
 
Upvote 0

inakigarm

Well-Known Member
Licensed User
Longtime User
Sorry, I can't access with your mail (Google wants to verificate access with sms/mail); maybe someone can give you any clue about the problem.
 
Upvote 0

stari

Active Member
Licensed User
Longtime User
Sorry, I can't access with your mail (Google wants to verificate access with sms/mail); maybe someone can give you any clue about the problem.
Hello,
i make new project, with new user and pass.
I make exactly as Erel explained.
But, maybe i'm stu..., hehe, no, please try this FB console.
user: app@elfemmit.com
pass: 1Vrtnica321
an my package name is: com.elfemmit
 
Upvote 0

stari

Active Member
Licensed User
Longtime User
Sorry, I can't access with your mail (Google wants to verificate access with sms/mail); maybe someone can give you any clue about the problem.
inakigram, i made exactly as Erel sugested. Can you , please, look on my account and see, what is wrong.
I tested with sending events for analytics, and i get the same error: success = fals
thks
 
Upvote 0

KMatle

Expert
Licensed User
Longtime User
1. The "Web Api Key" is used inside the GCM via the google-services.json to identify your app

This is the reason why you can receive messages via console without doing anything (so you did it right!!!!)

2. To send a GCM message you need the Server Key which is found here:



3. To send a message (to a single device) use this:

B4X:
 API_KEY="AIzaxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" '=Server Key!
  
   Dim Job As HttpJob
   Job.Initialize("Loc", Me)
   Dim m As Map = CreateMap("to": $"${devtoken}"$)
   Dim data As Map = CreateMap("nick": Nick, "loc": loc)
   m.Put("data", data)
   Dim jg As JSONGenerator
   jg.Initialize(m)
   Job.PostString("https://fcm.googleapis.com/fcm/send", jg.ToString)
   Job.GetRequest.SetContentType("application/json;charset=UTF-8")
   Job.GetRequest.SetHeader("Authorization", "key=" & API_KEY)

4. Where do I get the dev token from?

Call the subscribe sub in the Firebase service.

B4X:
Public Sub SubscribeToTopics
    Log("Subscribe")
   fm.SubscribeToTopic("all") 'subscribe = register and get the devices token. "all" is just an own topic. Could be anything
  
   Log (fm.Token)
  
End Sub

5. Security/Info

I never send a message from an app directly.

- One does not know the dev's tokens. So you need an own server where the users register (or: You want to send a message to Michael's device. How do you know the dev's token of Michael's mobile phone?)
- The server key can be extracted very easy from the app and then one can send messages, too (except you have other security options set)
- other stuff like databases, security, handle the messages, etc.
 
Upvote 0

stari

Active Member
Licensed User
Longtime User
Thks for instructions, @KMatle. I will try this on tusdey, now i'm on sailing.
 
Upvote 0

stari

Active Member
Licensed User
Longtime User
@KMatle, thank you. @Erel has explained, to take server key from cloud messaging. No, i missed this and have used wrong key. I realized this only from your picture.
Hm. I just been in years. Thank you again.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…