gpt4 book ai didi

django - 如何在 Django 中发送 Firebase 推送通知

转载 作者:行者123 更新时间:2023-12-05 09:11:56 29 4
gpt4 key购买 nike

我已经按照步骤操作了。

  • pip install fcm-django

编辑你的settings.py文件

INSTALLED_APPS = ("fcm_django")

FCM_DJANGO_SETTINGS = {
"FCM_SERVER_KEY": "[your api key]"
}

然后

  • manage.py 迁移

如何在 token 上发送推送消息??没看懂下面的方法

from fcm_django.models import FCMDevice
device = FCMDevice.objects.all().first()
device.send_message("Title", "Message")
device.send_message(data={"test": "test"})
device.send_message(title="Title", body="Message", icon=..., data={"test": "test"})

最佳答案

pip 安装 pyfcm

pip 安装 git+ https://github.com/olucurious/PyFCM.git

# Send to single device.
from pyfcm import FCMNotification

push_service = FCMNotification(api_key="<api-key>")

registration_id = "<device registration_id>"
message_title = "Uber update"
message_body = "Hi john, your customized news for today is ready"
result = push_service.notify_single_device(registration_id=registration_id, message_title=message_title, message_body=message_body)
print result

# Send to multiple devices by passing a list of ids.
registration_ids = ["<device registration_id 1>", "<device registration_id 2>", ...]
message_title = "Uber update"
message_body = "Hope you're having fun this weekend, don't forget to check today's news"
result = push_service.notify_multiple_devices(registration_ids=registration_ids, message_title=message_title, message_body=message_body)

print result

在 google 我自己得到这个结果并为更多信息工作后,使用这个链接 https://pypi.org/project/pyfcm/0.0.4/

关于django - 如何在 Django 中发送 Firebase 推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59355850/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com