Forked from ravishankarsingh1996/fcm_push_notification_python.py
Created
September 6, 2021 04:41
-
-
Save dublado/0130bdbcfe167a3e6d59eaf05c51406a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Install request module by running -> | |
# pip3 install requests | |
# Replace the deviceToken key with the device Token for which you want to send push notification. | |
# Replace serverToken key with your serverKey from Firebase Console | |
# Run script by -> | |
# python3 fcm_python.py | |
import requests | |
import json | |
serverToken = 'your server key here' | |
deviceToken = 'device token here' | |
headers = { | |
'Content-Type': 'application/json', | |
'Authorization': 'key=' + serverToken, | |
} | |
body = { | |
'notification': {'title': 'Sending push form python script', | |
'body': 'New Message' | |
}, | |
'to': | |
deviceToken, | |
'priority': 'high', | |
# 'data': dataPayLoad, | |
} | |
response = requests.post("https://fcm.googleapis.com/fcm/send",headers = headers, data=json.dumps(body)) | |
print(response.status_code) | |
print(response.json()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment