消息传递在Python firebaseadmin中不起作用

2024-06-21 20:22:47 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用python向firebase中的主题发送通知。然而,我有一个问题

这是错误消息:message = messaging.Message( NameError: name 'messaging' is not defined

代码如下:

import firebase_admin
from firebase_admin import credentials


cred = credentials.Certificate("path")
firebase_admin.initialize_app(cred)

topic = 'TestTopic'
def sendPush(title, msg):
    message = messaging.Message(
        data = {
            'title': 'TestTitle',
            'body': 'sometest',
        },
        topic=topic
    )

    response = messaging.send(message)


sendPush('hello', 'test')

非常感谢您的帮助。 多谢各位


Tags: import消息message主题topicadmintitle错误