使用 firebase 云消息发送通知失败,Python API

Failing sending notifications using firebase cloud messaging, Python API

阅读我编写的 Python 脚本的 Firebase 文档,以便向我的 Android 应用程序发送一些通知。

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)

授权信息存储在 GOOGLE_APPLICATION_CREDENTIALS env 变量中,该变量指向我从 firebase.google.com 下载的私钥 json 文件。

即使我得到消息 ID 作为输出并且没有显示错误消息,我也没有在我的 phone 上看到任何通知。只有当我通过 Web 应用程序使用 Firebase 控制台手动发送通知时,我才能成功收到通知 (firebase.google.com),但我需要使该过程自动化。手动发送时出现的通知告诉我我的应用成功订阅了主题,但我不明白为什么 Python API 不起作用。我认为这不是环境问题,因为我也尝试使用节点 API 并且得到相同的结果。有人有一些线索吗?我觉得我错过了什么。我运行我电脑里的脚本,不知道算不算数

我找到了一种显示通知的方法。事实证明,由于我正在使用 Flutter Framework 进行开发,因此 Android 应用只能通过 旧版应用服务器协议 处理通知:Firebase documentation legacy protocol

使用该方法最终显示通知。不知道iOS.

会不会出现同样的问题