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:
View attachment 49524
3. To send a message (to a single device) use this:
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.
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.