0

I'm working on django project in which i need to send notifications to the users using firebase admin sdk. but when ever i tried to send notification i see no logs for messaging.send_multicast(message). can anyone help me on this?

message = messaging.MulticastMessage(
 data={
 'data': str(self.data)
 },
 tokens=registration_tokens,
)
print('message', message)
response = messaging.send_multicast(message)
print('response', response.success_count, response.failure_count)
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
imran khan
  • 382
  • 3
  • 15

1 Answers1

0

The code above to send a multicast data message is correct and should work. Do you get any errors?

Also have you made sure to initialise the Firebase admin SDK with correct credentials:

import firebase_admin
from firebase_admin import credentials, messaging

cred = credentials.Certificate(<credentials_path>)
default_app = firebase_admin.initialize_app(cred)

If you want to send a notification that's visible on the user's phone, should use the notification attribute, like so:

message = messaging.MulticastMessage(
    notification=messaging.Notification(
        title="Notification Title",
        body="Notification Text",
    ),
    tokens=registration_tokens
)

response = messaging.send_multicast(message)
print('response', response.success_count, response.failure_count)
Ignas
  • 21
  • 2