Firebase Cloud Messaging registration token - Flutter and Django

Viewed 10

I am trying to send push notifications (iOS, Android, Web) to specific users when certain events happen in my app.

I am using the firebase_admin python plugin with Django, working properly for authentication and verifying jwt, but it is giving me this error when trying to send a Message/Notification from Django:

firebase_admin.exceptions.InvalidArgumentError: The registration token is not a valid FCM registration token

I am getting the token directly from my Flutter instance and sending it in the request body from Flutter to Django.

My method for getting the token from Flutter:

await FirebaseMessaging.instance.getToken().then((token) async {
    fcm_token = token!;
  }).catchError((e) {
    print(e);
  });

My python code that sends notification:

registration_token = self.context['request'].data["token"],

        # See documentation on defining a message payload.
        message = Message(
            notification=Notification(
                title='New Product Added',
                body='A new product called ' + validated_data['name'] + ' has been added to your account.',
            ),
            token=str(registration_token)
        )

        # Send a message to the device corresponding to the provided
        # registration token.
        response = send(message)

I have verified that the token being passed to Django is correct, by comparing it to what I am getting from Flutter

0 Answers
Related