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.