B4J Question FCM Admin Subscribe and Unsubscribe Topics

DonManfred

Expert
Licensed User
Longtime User
according to Docu it is possible
yes? I did not found anything in the Admin-Docu (Note that you did posted the WEB/JS Docu, not the Admin-Docu)

Edit to Add:

Warning: This API is currently only available for the Admin Node.js SDK. If you want to manage topic subscriptions from a non-Node.js server, you should use the HTTP APIs as explained in Manage relationship maps for multiple app instances. You can also subscribe devices to topics directly from the client SDKs (iOS, Android, Unity, C++).
 
Upvote 0

Alexander Stolte

Expert
Licensed User
Longtime User
Had this morning already written 2 functions, but he does not take the token.

B4X:
Private Sub SubscribeToTopic2(Token() As String, TopicName As String)
       
    Dim Job As HttpJob
    Job.Initialize("fcm", Me)
    Dim m As Map = CreateMap("to": $"/topics/${TopicName}"$, "registration_tokens":Token)
   
    Dim jg As JSONGenerator
    jg.Initialize(m)
   
    Job.PostString("https://iid.googleapis.com/iid/v1:batchAdd", jg.ToString)
    Job.GetRequest.SetContentType("application/json")
    Job.GetRequest.SetHeader("Authorization", "key=" & API_KEY)
   
End Sub

Private Sub UnsubscribeTopic2(Token() As String, TopicName As String)
       
    Dim Job As HttpJob
    Job.Initialize("fcm", Me)
    Dim m As Map = CreateMap("to": $"/topics/${TopicName}"$, "registration_tokens":Token)

    Dim jg As JSONGenerator
    jg.Initialize(m)
   
    Job.PostString("https://iid.googleapis.com/iid/v1:batchRemove", jg.ToString)
    Job.GetRequest.SetContentType("application/json")
    Job.GetRequest.SetHeader("Authorization", "key=" & API_KEY)
   
End Sub
 
Upvote 0

Alexander Stolte

Expert
Licensed User
Longtime User
Yes.

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@2a3046da, tag=java.lang.Object@2a098129
, httputils2service=null]
{"results":[{"error":"INVALID_ARGUMENT"}]}
Program terminated (StartMessageLoop was not called).

  • INVALID_ARGUMENT — The registration token provided is not valid for the Sender ID.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
The registration token provided is not valid for the Sender ID
You can see the Sender ID in the Console

The auth-token you provided does not belong to sender ID

API_KEY is the server key from:

SS-2017-04-07_08.10.47.png


The Sever Key you are using seems not to be correct.

Maybe you need to use the legacy server key!?
 
Upvote 0
Top