Size: 1170
Comment:
|
Size: 1820
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 36: | Line 36: |
=== single_dev_pyfcm.py === {{{#!highlight python #send push to target device with registered token getToken() #python single_dev_pyfcm.py "Test hello push" from pyfcm import FCMNotification import uuid import sys dev_token="eBSZS..." cloud_messaging_server_key ="AAAA0..." push_service = FCMNotification(api_key=cloud_messaging_server_key, proxy_dict=None) body = "Hello" if len(sys.argv)>1: body = sys.argv[1] data_message = { "body" : body, } res = push_service.notify_single_device(registration_id=dev_token, message_title="Title", message_body=body, data_message=data_message) print(res) }}} |
Firebase
Firebase is a platform developed by Google for creating mobile and web applications.
Cloud messaging
pyfcm
https://howto.lintel.in/push-notifications-using-python-via-fcm/
- pip install pyfcm
1 # the fcm client must subscribe a topic that matches the device uuid
2 from pyfcm import FCMNotification
3
4 cloud_messaging_server_key ="AAAA(...)" # missing data for the key
5 push_service = FCMNotification(api_key=cloud_messaging_server_key, proxy_dict=None)
6
7 message_body = "Hello"
8 data_message = {
9 "user" : "Mario",
10 "body" : message_body,
11 "chatRoom" : "PortugalVSDenmark"
12 }
13
14 device_uuid="8ab6abc19dc54262"
15
16 result = push_service.notify_topic_subscribers(topic_name=device_uuid,
17 message_body=message_body, data_message=data_message)
18 print(result)
single_dev_pyfcm.py
1 #send push to target device with registered token getToken()
2 #python single_dev_pyfcm.py "Test hello push"
3 from pyfcm import FCMNotification
4 import uuid
5 import sys
6
7 dev_token="eBSZS..."
8 cloud_messaging_server_key ="AAAA0..."
9 push_service = FCMNotification(api_key=cloud_messaging_server_key, proxy_dict=None)
10
11 body = "Hello"
12
13 if len(sys.argv)>1:
14 body = sys.argv[1]
15
16 data_message = {
17 "body" : body,
18 }
19
20 res = push_service.notify_single_device(registration_id=dev_token,
21 message_title="Title",
22 message_body=body, data_message=data_message)
23 print(res)