Created
March 28, 2020 23:25
-
-
Save ravishankarsingh1996/35e5af07ab0f7214d5ce2e930dc721dd 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()) |
if I pass an array of device tokens, will it work? Thanks in advanced.
Did it work?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How do I get a device token