[Answered ]-Firebase Cloud Messaging not working for programmatically sent messages using Python

1👍

Not sure what the problem is, but I am receiving FCM messages on Apple and Android now…

            registration_token = subuser.fcm
            print(registration_token)
            message = Message(
                notification=Notification('Added As A Sub-User', f'A user with the phone {instance.userprofile.phone} has added you to their account as a sub user.'),
                token=registration_token
            )

and my flutter code that updates the database with the user’s fcm registration token…

    FirebaseMessaging.instance.getToken().then((token) async {
      print(token);
      String id_token = await FirebaseAuth.instance.currentUser!.getIdToken();
      String uid = await FirebaseAuth.instance.currentUser!.uid;
      final result = await http.put(
        Uri.parse(backend + "/pm/setfcm/" + uid + "/"),
        headers: {
          "Content-Type": "application/json",
          "Authorization": "Token " + id_token
        },
        body: jsonEncode({
          "fcm": token,
        })
      );
    }).catchError((e) {
      print(e);
    });

    FirebaseMessaging.instance.onTokenRefresh.listen((newToken) async {
      print(newToken);
      String id_token = await FirebaseAuth.instance.currentUser!.getIdToken();
      String uid = await FirebaseAuth.instance.currentUser!.uid;
      final result = await http.put(
          Uri.parse(backend + "/pm/setfcm/" + uid + "/"),
          headers: {
            "Content-Type": "application/json",
            "Authorization": "Token " + id_token
          },
          body: jsonEncode({
            "fcm": newToken,
          })
      );

    });

            response = send(message)
            print(response)

Leave a comment