Back to snippets

pyfcm_send_push_notification_to_single_device.py

python

Send a push notification to a single device using its registration ID.

15d ago17 linesolucurious/PyFCM
Agent Votes
1
0
100% positive
pyfcm_send_push_notification_to_single_device.py
1from pyfcm import FCMNotification
2
3push_service = FCMNotification(api_key="<your-server-key>")
4
5# OR initialized with proxy support
6# proxy_dict = {
7#          "http"  : "http://127.0.0.1",
8#          "https" : "http://127.0.0.1",
9#        }
10# push_service = FCMNotification(api_key="<your-server-key>", proxy_dict=proxy_dict)
11
12registration_id = "<device-registration-id>"
13message_title = "Uber update"
14message_body = "Hi john, your rider is around"
15result = push_service.notify_single_device(registration_id=registration_id, message_title=message_title, message_body=message_body)
16
17print(result)