Search code examples
pythonfirebase-cloud-messagingfirebase-admin

FCM Send MulticastMessage


I run tihs code:

cred = credentials.Certificate('x.json')
firebase_admin.initialize_app(cred)
registration_tokens = [
    'GET REAL TOKEN1',
    'GET REAL TOKEN2',
]

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)

when run this code get error:

<a href=//www.google.com/><span id=logo aria-label=Google></span></a>
  <p><b>404.</b> <ins>That’s an error.</ins>
  <p>The requested URL <code>/batch</code> was not found on this server.  <ins>That’s all we know.</ins>

NOTE: I can send message to one user and work correctly:

messaging.Message()

Solution

  • Multicast messaging is no longer supported in Firebase Cloud Messaging. While your SDK version may still have a method for it, the endpoint that that method calls has been removed.

    From the Firebase documentation on sending messages to multiple devices:

    Important: The send methods described in this section were deprecated on June 21, 2023, and will be removed in June 2024. For protocol, instead use the standard HTTP v1 API send method, implementing your own batch send by iterating through the list of recipients and sending to each recipient's token. For Admin SDK methods, make sure to update to the next major version. See the Firebase FAQ for more information.

    I recommend upgrading to the latest version of the SDK you use, and checking what method most closely matches your needs there.

    This has been posted multiple times in the past week, so I recommend searching for relevant posts. One such post: