2

Reading the Firebase documentation I wrote that Python script in order to send some notifications to my Android app.

import firebase_admin 
from firebase_admin import credentials, messaging

#USING ENV VARIABLE: GOOGLE_APPLICATION_CREDENTIALS 
app = firebase_admin.initialize_app()

topic = 'uat-test' 
notification = messaging.Notification(title="Title", body="Body")

# See documentation on defining a message payload. 
message = messaging.Message(
    notification=notification,
    topic=topic, )

# Send a message to the devices subscribed to the provided topic. 
messaging.send(message)

# Response is a message ID string. 
print('Successfully sent message:', message)

The auth information are stored into GOOGLE_APPLICATION_CREDENTIALS env variable that point to the private key json file I downloaded from firebase.google.com.

Even if I get as output the message ID and no error message is shown, I don't see any notification on my phone. I successfully get the notification only if I manually send it using the Firebase console through the web app (firebase.google.com) but I need to automatize the process. The notification coming when manually dispatched tells me that my app successfully subscribe to the topic, but I can't get why the Python API doesn't work. I don't think is an environment problem since I had a try with the Node API too and I get the same results. Anyone has some clue ? I feel that I'm missing something. I run the script from my computer, I don't know if it is something that can count.

lucataglia
  • 728
  • 5
  • 18
  • Perhaps you can look into my answer at https://stackoverflow.com/questions/65377912/pushing-notification-to-all-users-in-firebase/70232919#70232919 – Jason Lim Ji Chen Dec 05 '21 at 11:57

1 Answers1

2

I found a way to show notifications. It turn out that since I'm developing using Flutter Framework, the Android app can handle notifications only through the legacy app server protocols: Firebase documentation legacy protocol

Using that approach the notifications are finally shown. I don't know if there will be the same problem with iOS.

lucataglia
  • 728
  • 5
  • 18