Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How send Firebase Push notification in django

I have followed the steps.

  • pip install fcm-django

Edit your settings.py file

INSTALLED_APPS = ("fcm_django")

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

and then

  • manage.py migrate

How do I send push messages on tokens ?? I didn't understand the following method

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"})
like image 608
Sohail Ahmad Avatar asked Dec 29 '25 22:12

Sohail Ahmad


1 Answers

pip install pyfcm

OR

pip install 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

OR

# 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

after google myself getting this result and its working for more info use this link https://pypi.org/project/pyfcm/0.0.4/

like image 176
Sohail Ahmad Avatar answered Dec 31 '25 12:12

Sohail Ahmad