Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dublado/0130bdbcfe167a3e6d59eaf05c51406a to your computer and use it in GitHub Desktop.
Save dublado/0130bdbcfe167a3e6d59eaf05c51406a to your computer and use it in GitHub Desktop.
## 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