Hi Perhaps I am doing something wrong
You can just use the usertoken in the Request to send a Message to this specific ID. NO NEED to use registertopic.
What I have done
1. Install the Push example code on my phone (it subscribes to "general" topic - and runs it in both debug and and release). The only addition to the code is show the device token on the screen (so I can check it has not changed).
2. Run up the B4j push sender "FCMPush" example code, the only change is the inclusion of the device ID/token and the FCM project files.
Sub Process_Globals
Private Const ProjectId As String = "pushtest2023" ' Taken from firebase project settings.
Private ServiceAccountFilePath As String = "C:\Projects\B4j_DEV\FCMPush\FireBaseKeyFiles\pushtest2023-firebase-adminsdk-fbsvc-ff4b7ad120.json"
Private Token As String
End Sub
Sub AppStart (Args() As String)
Dim deviceID As String = "dj7Wz7ukQYe83L-fP4WuZl:APA91bE0NQJtZKbauGBoBEENrigNPEAciGodyMHSLPApYdVMZ-Z58kjU88zLnRHKaxiwoiRxv7HaloIWNzLXf3pLswi6U26b14eyTYrWGKXZR9Gc1_naXik"
Send("general", "this Is the new 012 title", "And this is the new 012 body")
' Send(deviceID, "Title 001", "Body 001")
StartMessageLoop
End Sub
3. When Line #11 included and line #13 commented out, it works (the push message is shown on the phone)
And the log shows
----------------------
Waiting for debugger to connect...
Program started.
{
"message": {
"data": {
"title": "this Is the new 012 title",
"body": "And this is the new 012 body"
},
"android": {
"priority": "high"
},
"topic": "general"
}
}
{
"name": "projects/pushtest2023/messages/1204319572461093342"
}
--------
4. However, when #11 is commented out and line #13 is included (push message uses the phone device's ID/token - which I pasted across - so hopefully correct) - It does not work and I get the following error message in the log.
----------
Waiting for debugger to connect...
Program started.
{
"message": {
"data": {
"title": "Title 001",
"body": "Body 001"
},
"android": {
"priority": "high"
},
"topic": "dj7Wz7ukQYe83L-fP4WuZl:APA91bE0NQJtZKbauGBoBEENrigNPEAciGodyMHSLPApYdVMZ-Z58kjU88zLnRHKaxiwoiRxv7HaloIWNzLXf3pLswi6U26b14eyTYrWGKXZR9Gc1_naXik"
}
}
ResponseError. Reason: , Response: {
"error": {
"code": 400,
"message": "Request contains an invalid argument.",
"status": "INVALID_ARGUMENT",
"details": [
{
"@type": "type.googleapis.com/google.firebase.fcm.v1.FcmError",
"errorCode": "INVALID_ARGUMENT"
},
{
"@type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [
{
"field": "message.token",
"description": "Invalid registration token"
}
]
}
]
}
}
------------------------
It looks to me (from the error response message) that device token for the phone could wrong, but I am sure it is correct as it was pasted it across directly.
Any suggestions?
Kind regards
Dave