python - Firebase 管理员发送多播没有被调用或工作
问题描述
我正在开发 django 项目,在该项目中我需要使用 firebase admin sdk 向用户发送通知。但是当我尝试发送通知时,我看不到messaging.send_multicast(message)的日志。谁可以帮我这个事?
message = messaging.MulticastMessage(
data={
'data': str(self.data)
},
tokens=registration_tokens,
)
print('message', message)
response = messaging.send_multicast(message)
print('response', response.success_count, response.failure_count)
解决方案
上面发送多播数据消息的代码是正确的,应该可以工作。你有任何错误吗?
您还确保使用正确的凭据初始化 Firebase 管理 SDK:
import firebase_admin
from firebase_admin import credentials, messaging
cred = credentials.Certificate(<credentials_path>)
default_app = firebase_admin.initialize_app(cred)
如果要发送在用户手机上可见的通知,应使用该notification
属性,如下所示:
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)
推荐阅读
- numpy - 为什么当我创建一个随机数组时会出现负值 - “np.random.rand”
- django - 在图形右侧绘制短划线图形输入
- c# - 如何控制在主菜单中所做的音频更改也应用于游戏场景音频设置?
- java - Eclipse - 调试器不会在 xTend 代码断点处停止,但可以在 java 代码断点处停止
- php - Laravel 错误:找不到用于多重身份验证的类 'App\Http\Controllers\Auth\Auth'
- swift - 如何在 Swift Xcode 中取消 Firebase 查询
- windows - 如何知道 Windows 驱动程序字母更改
- java - Android Studio-Java RecyclerView 显示的视图(持有者)多于房间数据库中的行数
- amazon-web-services - 嵌套工作流 - 请求中包含的安全令牌无效
- javascript - 如何在西班牙语中添加 MultiDatesPicker?